r19329 - gnucash/trunk/src - Move the business object implementations from separate module into the main gnucash engine.

Christian Stimming cstim at code.gnucash.org
Sat Jul 3 17:53:22 EDT 2010


Author: cstim
Date: 2010-07-03 17:53:22 -0400 (Sat, 03 Jul 2010)
New Revision: 19329
Trac: http://svn.gnucash.org/trac/changeset/19329

Added:
   gnucash/trunk/src/engine/business-core.i
   gnucash/trunk/src/engine/gncAddress.c
   gnucash/trunk/src/engine/gncAddress.h
   gnucash/trunk/src/engine/gncAddressP.h
   gnucash/trunk/src/engine/gncBillTerm.c
   gnucash/trunk/src/engine/gncBillTerm.h
   gnucash/trunk/src/engine/gncBillTermP.h
   gnucash/trunk/src/engine/gncBusGuile.c
   gnucash/trunk/src/engine/gncBusGuile.h
   gnucash/trunk/src/engine/gncBusPeriod.c
   gnucash/trunk/src/engine/gncBusiness.c
   gnucash/trunk/src/engine/gncBusiness.h
   gnucash/trunk/src/engine/gncCustomer.c
   gnucash/trunk/src/engine/gncCustomer.h
   gnucash/trunk/src/engine/gncCustomerP.h
   gnucash/trunk/src/engine/gncEmployee.c
   gnucash/trunk/src/engine/gncEmployee.h
   gnucash/trunk/src/engine/gncEmployeeP.h
   gnucash/trunk/src/engine/gncEntry.c
   gnucash/trunk/src/engine/gncEntry.h
   gnucash/trunk/src/engine/gncEntryP.h
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
   gnucash/trunk/src/engine/gncInvoiceP.h
   gnucash/trunk/src/engine/gncJob.c
   gnucash/trunk/src/engine/gncJob.h
   gnucash/trunk/src/engine/gncJobP.h
   gnucash/trunk/src/engine/gncOrder.c
   gnucash/trunk/src/engine/gncOrder.h
   gnucash/trunk/src/engine/gncOrderP.h
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
   gnucash/trunk/src/engine/gncOwnerP.h
   gnucash/trunk/src/engine/gncTaxTable.c
   gnucash/trunk/src/engine/gncTaxTable.h
   gnucash/trunk/src/engine/gncTaxTableP.h
   gnucash/trunk/src/engine/gncVendor.c
   gnucash/trunk/src/engine/gncVendor.h
   gnucash/trunk/src/engine/gncVendorP.h
Removed:
   gnucash/trunk/src/business/business-core/business-core.i
   gnucash/trunk/src/business/business-core/gncAddress.c
   gnucash/trunk/src/business/business-core/gncAddress.h
   gnucash/trunk/src/business/business-core/gncAddressP.h
   gnucash/trunk/src/business/business-core/gncBillTerm.c
   gnucash/trunk/src/business/business-core/gncBillTerm.h
   gnucash/trunk/src/business/business-core/gncBillTermP.h
   gnucash/trunk/src/business/business-core/gncBusGuile.c
   gnucash/trunk/src/business/business-core/gncBusGuile.h
   gnucash/trunk/src/business/business-core/gncBusPeriod.c
   gnucash/trunk/src/business/business-core/gncBusiness.c
   gnucash/trunk/src/business/business-core/gncBusiness.h
   gnucash/trunk/src/business/business-core/gncCustomer.c
   gnucash/trunk/src/business/business-core/gncCustomer.h
   gnucash/trunk/src/business/business-core/gncCustomerP.h
   gnucash/trunk/src/business/business-core/gncEmployee.c
   gnucash/trunk/src/business/business-core/gncEmployee.h
   gnucash/trunk/src/business/business-core/gncEmployeeP.h
   gnucash/trunk/src/business/business-core/gncEntry.c
   gnucash/trunk/src/business/business-core/gncEntry.h
   gnucash/trunk/src/business/business-core/gncEntryP.h
   gnucash/trunk/src/business/business-core/gncInvoice.c
   gnucash/trunk/src/business/business-core/gncInvoice.h
   gnucash/trunk/src/business/business-core/gncInvoiceP.h
   gnucash/trunk/src/business/business-core/gncJob.c
   gnucash/trunk/src/business/business-core/gncJob.h
   gnucash/trunk/src/business/business-core/gncJobP.h
   gnucash/trunk/src/business/business-core/gncOrder.c
   gnucash/trunk/src/business/business-core/gncOrder.h
   gnucash/trunk/src/business/business-core/gncOrderP.h
   gnucash/trunk/src/business/business-core/gncOwner.c
   gnucash/trunk/src/business/business-core/gncOwner.h
   gnucash/trunk/src/business/business-core/gncOwnerP.h
   gnucash/trunk/src/business/business-core/gncTaxTable.c
   gnucash/trunk/src/business/business-core/gncTaxTable.h
   gnucash/trunk/src/business/business-core/gncTaxTableP.h
   gnucash/trunk/src/business/business-core/gncVendor.c
   gnucash/trunk/src/business/business-core/gncVendor.h
   gnucash/trunk/src/business/business-core/gncVendorP.h
Modified:
   gnucash/trunk/src/business/business-core/CMakeLists.txt
   gnucash/trunk/src/business/business-core/Makefile.am
   gnucash/trunk/src/engine/CMakeLists.txt
   gnucash/trunk/src/engine/Makefile.am
   gnucash/trunk/src/gnc/main.cpp
Log:
Move the business object implementations from separate module into the main gnucash engine.

Modified: gnucash/trunk/src/business/business-core/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/business/business-core/CMakeLists.txt	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/CMakeLists.txt	2010-07-03 21:53:22 UTC (rev 19329)
@@ -18,25 +18,8 @@
 INCLUDE_DIRECTORIES (${CMAKE_CURRENT_SOURCE_DIR}) # when building swig-core-utils.c
 INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}) # for gncla-dir.h
 
-SET (SWIG_BUSINESS_CORE_C ${CMAKE_CURRENT_BINARY_DIR}/swig-business-core.c)
-GNC_ADD_SWIG_COMMAND (${SWIG_BUSINESS_CORE_C} ${CMAKE_CURRENT_SOURCE_DIR}/business-core.i)
-
 SET (libgnc_business_core_SOURCES
-  gncAddress.c
-  gncBillTerm.c
-  gncBusGuile.c
-  gncBusiness.c
-  gncCustomer.c
-  gncEmployee.c
-  gncEntry.c
-  gncInvoice.c
-  gncJob.c
-  gncOrder.c
-  gncOwner.c
-  gncTaxTable.c
-  gncVendor.c
   gncmod-business-core.c
-  ${SWIG_BUSINESS_CORE_C}
 )
 
 SET (libgnc_business_core_xml_SOURCES
@@ -55,30 +38,6 @@
 )
 
 SET (libgnc_business_core_HEADERS
-  gncAddress.h
-  gncAddressP.h
-  gncBillTerm.h
-  gncBillTermP.h
-  gncBusGuile.h
-  gncBusiness.h
-  gncCustomer.h
-  gncCustomerP.h
-  gncEmployee.h
-  gncEmployeeP.h
-  gncEntry.h
-  gncEntryP.h
-  gncInvoice.h
-  gncInvoiceP.h
-  gncJob.h
-  gncJobP.h
-  gncOrder.h
-  gncOrderP.h
-  gncOwner.h
-  gncOwnerP.h
-  gncTaxTable.h
-  gncTaxTableP.h
-  gncVendor.h
-  gncVendorP.h
 )
 
 ADD_LIBRARY (business-core

Modified: gnucash/trunk/src/business/business-core/Makefile.am
===================================================================
--- gnucash/trunk/src/business/business-core/Makefile.am	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/Makefile.am	2010-07-03 21:53:22 UTC (rev 19329)
@@ -12,47 +12,9 @@
   ${GLIB_CFLAGS}
 
 libgncmod_business_core_la_SOURCES = \
-  swig-business-core.c \
-  gncBusGuile.c \
-  gncmod-business-core.c \
-  gncAddress.c \
-  gncBillTerm.c \
-  gncBusiness.c \
-  gncCustomer.c \
-  gncEmployee.c \
-  gncEntry.c \
-  gncInvoice.c \
-  gncJob.c \
-  gncOrder.c \
-  gncOwner.c \
-  gncTaxTable.c \
-  gncVendor.c
+  gncmod-business-core.c
 
-noinst_HEADERS = \
-  gncAddress.h \
-  gncAddressP.h \
-  gncBillTerm.h \
-  gncBillTermP.h \
-  gncBusiness.h \
-  gncBusGuile.h \
-  gncCustomer.h \
-  gncCustomerP.h \
-  gncEmployee.h \
-  gncEmployeeP.h \
-  gncEntry.h \
-  gncEntryP.h \
-  gncInvoice.h \
-  gncInvoiceP.h \
-  gncJob.h \
-  gncJobP.h \
-  gncOrder.h \
-  gncOrderP.h \
-  gncOwner.h \
-  gncOwnerP.h \
-  gncTaxTable.h \
-  gncTaxTableP.h \
-  gncVendor.h \
-  gncVendorP.h
+noinst_HEADERS =
 
 libgncmod_business_core_la_LDFLAGS = -avoid-version
 
@@ -66,17 +28,10 @@
 
 # business-core-helpers.c
 
-if BUILDING_FROM_SVN
-swig-business-core.c: business-core.i ${noinst_HEADERS} \
-                      ${top_srcdir}/src/base-typemaps.i
-	$(SWIG) -guile $(SWIG_ARGS) -Linkage module \
-	-I${top_srcdir}/src -o $@ $<
-endif
-
 gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash
 gncmod_DATA = business-core.scm
 
-EXTRA_DIST = business-core.i ${gncmod_DATA}
+EXTRA_DIST = ${gncmod_DATA}
 
 if GNUCASH_SEPARATE_BUILDDIR
 #For executing test cases
@@ -99,6 +54,6 @@
 
 noinst_DATA = .scm-links
 CLEANFILES = gnucash .scm-links ${SCM_FILE_LINKS}
-MAINTAINERCLEANFILES = swig-business-core.c
+MAINTAINERCLEANFILES =
 
 INCLUDES = -DG_LOG_DOMAIN=\"gnc.business.core\"

Deleted: gnucash/trunk/src/business/business-core/business-core.i
===================================================================
--- gnucash/trunk/src/business/business-core/business-core.i	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/business-core.i	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,168 +0,0 @@
-%module sw_business_core
-%{
-/* Includes the header in the wrapper code */
-#include <config.h>
-#include <guile-mappings.h>
-#include <gncAddress.h>
-#include <gncBillTerm.h>
-#include <gncCustomer.h>
-#include <gncEmployee.h>
-#include <gncEntry.h>
-#include <gncInvoice.h>
-#include <gncJob.h>
-#include <gncOrder.h>
-#include <gncOwner.h>
-#include <gncTaxTable.h>
-#include <gncVendor.h>
-#include <gncBusGuile.h>
-#ifdef _MSC_VER
-# define snprintf _snprintf
-#endif
-#include "engine-helpers.h"
-#include "gncBusGuile.h"
-
-/* Disable -Waddress.  GCC 4.2 warns (and fails to compile with -Werror) when
- * passing the address of a guid on the stack to QOF_BOOK_LOOKUP_ENTITY via
- * gncInvoiceLookup and friends.  When the macro gets inlined, the compiler
- * emits a warning that the guid null pointer test is always true.
- */
-#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
-#    pragma GCC diagnostic warning "-Waddress"
-#endif
-
-SCM scm_init_sw_business_core_module (void);
-%}
-
-%import "base-typemaps.i"
-
-%rename(gncOwnerReturnGUID) gncOwnerRetGUID;
-
-%inline %{
-static GncGUID gncTaxTableReturnGUID(GncTaxTable *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncGUID gncInvoiceReturnGUID(GncInvoice *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncGUID gncJobReturnGUID(GncJob *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncGUID gncVendorReturnGUID(GncVendor *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncGUID gncCustomerReturnGUID(GncCustomer *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncGUID gncEmployeeReturnGUID(GncEmployee *x)
-{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
-
-static GncTaxTable * gncTaxTableLookupFlip(GncGUID g, QofBook *b)
-{ return gncTaxTableLookup(b, &g); }
-
-static GncInvoice * gncInvoiceLookupFlip(GncGUID g, QofBook *b)
-{ return gncInvoiceLookup(b, &g); }
-
-static GncJob * gncJobLookupFlip(GncGUID g, QofBook *b)
-{ return gncJobLookup(b, &g); }
-
-static GncVendor * gncVendorLookupFlip(GncGUID g, QofBook *b)
-{ return gncVendorLookup(b, &g); }
-
-static GncCustomer * gncCustomerLookupFlip(GncGUID g, QofBook *b)
-{ return gncCustomerLookup(b, &g); }
-
-static GncEmployee * gncEmployeeLookupFlip(GncGUID g, QofBook *b)
-{ return gncEmployeeLookup(b, &g); }
-
-%}
-
-GLIST_HELPER_INOUT(EntryList, SWIGTYPE_p__gncEntry);
-GLIST_HELPER_INOUT(GncTaxTableEntryList, SWIGTYPE_p__gncTaxTableEntry);
-
-%typemap(in) GncAccountValue * "$1 = gnc_scm_to_account_value_ptr($input);"
-%typemap(out) GncAccountValue * "$result = gnc_account_value_ptr_to_scm($1);"
-%typemap(in) AccountValueList * {
-  SCM list = $input;
-  GList *c_list = NULL;
-
-  while (!scm_is_null(list)) {
-        GncAccountValue *p;
-
-        SCM p_scm = SCM_CAR(list);
-        if (scm_is_false(p_scm) || scm_is_null(p_scm))
-           p = NULL;
-        else
-           p = gnc_scm_to_account_value_ptr(p_scm);
-
-        c_list = g_list_prepend(c_list, p);
-        list = SCM_CDR(list);
-  }
-
-  $1 = g_list_reverse(c_list);
-}
-%typemap(out) AccountValueList * {
-  SCM list = SCM_EOL;
-  GList *node;
-
-  for (node = $1; node; node = node->next)
-    list = scm_cons(gnc_account_value_ptr_to_scm(node->data), list);
-
-  $result = scm_reverse(list);
-}
-
-
-
-/* Parse the header files to generate wrappers */
-%include <gncAddress.h>
-%include <gncBillTerm.h>
-%include <gncCustomer.h>
-%include <gncEmployee.h>
-%include <gncEntry.h>
-%include <gncInvoice.h>
-%include <gncJob.h>
-%include <gncOrder.h>
-%include <gncOwner.h>
-%include <gncTaxTable.h>
-%include <gncVendor.h>
-%include <gncBusGuile.h>
-
-#define URL_TYPE_CUSTOMER GNC_ID_CUSTOMER
-#define URL_TYPE_VENDOR GNC_ID_VENDOR
-#define URL_TYPE_EMPLOYEE GNC_ID_EMPLOYEE
-#define URL_TYPE_JOB GNC_ID_JOB
-#define URL_TYPE_INVOICE GNC_ID_INVOICE
-// not exactly clean
-#define URL_TYPE_OWNERREPORT "owner-report"
-
-%init {
-  {
-    char tmp[100];
-
-#define SET_ENUM(e) snprintf(tmp, 100, "(set! %s (%s))", (e), (e));  \
-    scm_c_eval_string(tmp);
-
-    SET_ENUM("GNC-OWNER-CUSTOMER");
-    SET_ENUM("GNC-OWNER-VENDOR");
-    SET_ENUM("GNC-OWNER-EMPLOYEE");
-    SET_ENUM("GNC-OWNER-JOB");
-    SET_ENUM("GNC-AMT-TYPE-VALUE");
-    SET_ENUM("GNC-AMT-TYPE-PERCENT");
-
-    SET_ENUM("URL-TYPE-CUSTOMER");
-    SET_ENUM("URL-TYPE-VENDOR");
-    SET_ENUM("URL-TYPE-EMPLOYEE");
-    SET_ENUM("URL-TYPE-JOB");
-    SET_ENUM("URL-TYPE-INVOICE");
-    SET_ENUM("URL-TYPE-OWNERREPORT");
-
-    SET_ENUM("INVOICE-FROM-TXN");
-    SET_ENUM("INVOICE-FROM-LOT");
-    SET_ENUM("INVOICE-OWNER");
-    SET_ENUM("OWNER-PARENTG");
-    SET_ENUM("OWNER-FROM-LOT");
-
-
-#undefine SET_ENUM
-  }
-
-}

Deleted: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncAddress.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,691 +0,0 @@
-/********************************************************************\
- * gncAddress.c -- an Address object                                *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-
-#include "gncAddress.h"
-#include "gncAddressP.h"
-#include "gncCustomerP.h"
-
-struct _gncAddress
-{
-    QofInstance inst;
-
-    QofBook *	book;
-    QofInstance * parent;
-    gboolean	dirty;
-    char *	name;
-    char *	addr1;
-    char *	addr2;
-    char *	addr3;
-    char *	addr4;
-    char *	phone;
-    char *	fax;
-    char *	email;
-};
-
-struct _gncAddressClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME	GNC_ADDRESS_MODULE_NAME
-
-G_INLINE_FUNC void mark_address (GncAddress *address);
-void mark_address (GncAddress *address)
-{
-    address->dirty = TRUE;
-
-    qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
-    qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
-}
-
-enum
-{
-    PROP_0,
-    PROP_NAME,
-    PROP_ADDR1,
-    PROP_ADDR2,
-    PROP_ADDR3,
-    PROP_ADDR4,
-    PROP_PHONE,
-    PROP_FAX,
-    PROP_EMAIL
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncAddress, gnc_address, QOF_TYPE_INSTANCE);
-
-static void
-gnc_address_init(GncAddress* addr)
-{
-}
-
-static void
-gnc_address_dispose(GObject *addrp)
-{
-    G_OBJECT_CLASS(gnc_address_parent_class)->dispose(addrp);
-}
-
-static void
-gnc_address_finalize(GObject* addrp)
-{
-    G_OBJECT_CLASS(gnc_address_parent_class)->finalize(addrp);
-}
-
-static void
-gnc_address_get_property (GObject         *object,
-                          guint            prop_id,
-                          GValue          *value,
-                          GParamSpec      *pspec)
-{
-    GncAddress *address;
-
-    g_return_if_fail(GNC_IS_ADDRESS(object));
-
-    address = GNC_ADDRESS(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, address->name);
-        break;
-    case PROP_ADDR1:
-        g_value_set_string(value, address->addr1);
-        break;
-    case PROP_ADDR2:
-        g_value_set_string(value, address->addr2);
-        break;
-    case PROP_ADDR3:
-        g_value_set_string(value, address->addr3);
-        break;
-    case PROP_ADDR4:
-        g_value_set_string(value, address->addr4);
-        break;
-    case PROP_PHONE:
-        g_value_set_string(value, address->phone);
-        break;
-    case PROP_FAX:
-        g_value_set_string(value, address->fax);
-        break;
-    case PROP_EMAIL:
-        g_value_set_string(value, address->email);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_address_set_property (GObject         *object,
-                          guint            prop_id,
-                          const GValue          *value,
-                          GParamSpec      *pspec)
-{
-    GncAddress *address;
-
-    g_return_if_fail(GNC_IS_ADDRESS(object));
-
-    address = GNC_ADDRESS(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncAddressSetName(address, g_value_get_string(value));
-        break;
-    case PROP_ADDR1:
-        gncAddressSetAddr1(address, g_value_get_string(value));
-        break;
-    case PROP_ADDR2:
-        gncAddressSetAddr2(address, g_value_get_string(value));
-        break;
-    case PROP_ADDR3:
-        gncAddressSetAddr3(address, g_value_get_string(value));
-        break;
-    case PROP_ADDR4:
-        gncAddressSetAddr4(address, g_value_get_string(value));
-        break;
-    case PROP_PHONE:
-        gncAddressSetPhone(address, g_value_get_string(value));
-        break;
-    case PROP_FAX:
-        gncAddressSetFax(address, g_value_get_string(value));
-        break;
-    case PROP_EMAIL:
-        gncAddressSetEmail(address, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    /* Refers to nothing.  The parent field doesn't really count since the parent knows which address
-       belongs to it. */
-    return NULL;
-}
-
-static void
-gnc_address_class_init (GncAddressClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_address_dispose;
-    gobject_class->finalize = gnc_address_finalize;
-    gobject_class->set_property = gnc_address_set_property;
-    gobject_class->get_property = gnc_address_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = NULL;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "Address Name",
-                          "The address name is an arbitrary string "
-                          "assigned by the user.  It is intended to "
-                          "a short string to identify the address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_ADDR1,
-     g_param_spec_string ("addr1",
-                          "Address Line 1",
-                          "The address line 1 is an arbitrary string "
-                          "assigned by the user.  It is the first "
-                          "line of the address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_ADDR2,
-     g_param_spec_string ("addr2",
-                          "Address Line 2",
-                          "The address line 2 is an arbitrary string "
-                          "assigned by the user.  It is the second "
-                          "line of the address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_ADDR3,
-     g_param_spec_string ("addr3",
-                          "Address Line 3",
-                          "The address line 3 is an arbitrary string "
-                          "assigned by the user.  It is the third "
-                          "line of the address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_ADDR4,
-     g_param_spec_string ("addr4",
-                          "Address Line 4",
-                          "The address line 4 is an arbitrary string "
-                          "assigned by the user.  It is the fourth "
-                          "line of the address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_PHONE,
-     g_param_spec_string ("phone",
-                          "Phone",
-                          "The phone number is the number at this address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_FAX,
-     g_param_spec_string ("fax",
-                          "Fax",
-                          "The fax number at this address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_EMAIL,
-     g_param_spec_string ("email",
-                          "E-mail address",
-                          "The e-mail address at this address.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy functions */
-
-GncAddress *
-gncAddressCreate (QofBook *book, QofInstance *prnt)
-{
-    GncAddress *addr;
-
-    if (!book) return NULL;
-
-    addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
-    qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
-    addr->book = book;
-    addr->dirty = FALSE;
-    addr->parent = prnt;
-
-    addr->name = CACHE_INSERT ("");
-    addr->addr1 = CACHE_INSERT ("");
-    addr->addr2 = CACHE_INSERT ("");
-    addr->addr3 = CACHE_INSERT ("");
-    addr->addr4 = CACHE_INSERT ("");
-    addr->phone = CACHE_INSERT ("");
-    addr->fax = CACHE_INSERT ("");
-    addr->email = CACHE_INSERT ("");
-
-    return addr;
-}
-
-static GncAddress *
-qofAddressCreate (QofBook *book)
-{
-    /* The address will get set later by another function */
-    return gncAddressCreate(book, NULL);
-}
-
-static void
-qofAddressSetOwner(GncAddress *addr, QofInstance *ent)
-{
-    if (!addr || !ent)
-    {
-        return;
-    }
-    if (addr->parent == NULL)
-    {
-        addr->parent = ent;
-    }
-}
-
-static QofInstance*
-qofAddressGetOwner(const GncAddress *addr)
-{
-
-    if (!addr)
-    {
-        return NULL;
-    }
-    return addr->parent;
-}
-
-GncAddress *
-gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book)
-{
-    GncAddress *addr;
-
-    if (!book) return NULL;
-
-    addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
-    qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
-    addr->book = book;
-    addr->dirty = TRUE;
-    addr->parent = new_parent;
-
-    addr->name = CACHE_INSERT (from->name);
-    addr->addr1 = CACHE_INSERT (from->addr1);
-    addr->addr2 = CACHE_INSERT (from->addr2);
-    addr->addr3 = CACHE_INSERT (from->addr3);
-    addr->addr4 = CACHE_INSERT (from->addr4);
-    addr->phone = CACHE_INSERT (from->phone);
-    addr->fax = CACHE_INSERT (from->fax);
-    addr->email = CACHE_INSERT (from->email);
-
-    return addr;
-}
-
-void
-gncAddressDestroy (GncAddress *addr)
-{
-    if (!addr) return;
-    qof_instance_set_destroying(addr, TRUE);
-    gncAddressCommitEdit (addr);
-}
-
-static void
-gncAddressFree (GncAddress *addr)
-{
-    if (!addr) return;
-
-    qof_event_gen (&addr->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (addr->name);
-    CACHE_REMOVE (addr->addr1);
-    CACHE_REMOVE (addr->addr2);
-    CACHE_REMOVE (addr->addr3);
-    CACHE_REMOVE (addr->addr4);
-    CACHE_REMOVE (addr->phone);
-    CACHE_REMOVE (addr->fax);
-    CACHE_REMOVE (addr->email);
-
-    /* qof_instance_release (&addr->inst); */
-    g_object_unref (addr);
-}
-
-
-/* Set functions */
-
-#define SET_STR(obj, member, str) { \
-	char * tmp; \
-	\
-	if (member == str) return; \
-	if (!safe_strcmp (member, str)) return; \
-	gncAddressBeginEdit (obj); \
-	tmp = CACHE_INSERT (str); \
-	CACHE_REMOVE (member); \
-	member = tmp; \
-	}
-
-void gncAddressSetName (GncAddress *addr, const char *name)
-{
-    if (!addr) return;
-    if (!name) return;
-    SET_STR(addr, addr->name, name);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetAddr1 (GncAddress *addr, const char *addr1)
-{
-    if (!addr) return;
-    if (!addr1) return;
-    SET_STR(addr, addr->addr1, addr1);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetAddr2 (GncAddress *addr, const char *addr2)
-{
-    if (!addr) return;
-    if (!addr2) return;
-    SET_STR(addr, addr->addr2, addr2);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetAddr3 (GncAddress *addr, const char *addr3)
-{
-    if (!addr) return;
-    if (!addr3) return;
-    SET_STR(addr, addr->addr3, addr3);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetAddr4 (GncAddress *addr, const char *addr4)
-{
-    if (!addr) return;
-    if (!addr4) return;
-    SET_STR(addr, addr->addr4, addr4);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetPhone (GncAddress *addr, const char *phone)
-{
-    if (!addr) return;
-    if (!phone) return;
-    SET_STR(addr, addr->phone, phone);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetFax (GncAddress *addr, const char *fax)
-{
-    if (!addr) return;
-    if (!fax) return;
-    SET_STR(addr, addr->fax, fax);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressSetEmail (GncAddress *addr, const char *email)
-{
-    if (!addr) return;
-    if (!email) return;
-    SET_STR(addr, addr->email, email);
-    mark_address (addr);
-    gncAddressCommitEdit (addr);
-}
-
-void gncAddressBeginEdit (GncAddress *addr)
-{
-    qof_begin_edit (&addr->inst);
-}
-
-static void gncAddressOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("Address QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncAddressOnDone (QofInstance *addr) { }
-
-static void address_free (QofInstance *inst)
-{
-    GncAddress *addr = (GncAddress *) inst;
-    gncAddressFree (addr);
-}
-
-void gncAddressCommitEdit (GncAddress *addr)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(addr))) return;
-    qof_commit_edit_part2 (&addr->inst, gncAddressOnError,
-                           gncAddressOnDone, address_free);
-}
-
-
-/* Get Functions */
-
-const char * gncAddressGetName (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->name;
-}
-
-const char * gncAddressGetAddr1 (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->addr1;
-}
-
-const char * gncAddressGetAddr2 (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->addr2;
-}
-
-const char * gncAddressGetAddr3 (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->addr3;
-}
-
-const char * gncAddressGetAddr4 (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->addr4;
-}
-
-const char * gncAddressGetPhone (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->phone;
-}
-
-const char * gncAddressGetFax (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->fax;
-}
-
-const char * gncAddressGetEmail (const GncAddress *addr)
-{
-    if (!addr) return NULL;
-    return addr->email;
-}
-
-gboolean gncAddressIsDirty (const GncAddress *addr)
-{
-    if (!addr) return FALSE;
-    return addr->dirty;
-}
-
-void gncAddressClearDirty (GncAddress *addr)
-{
-    if (!addr) return;
-    addr->dirty = FALSE;
-}
-
-int gncAddressCompare (const GncAddress *a, const GncAddress *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    return safe_strcmp (a->name, b->name);
-}
-
-gboolean
-gncAddressEqual(const GncAddress* a, const GncAddress* b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
-    g_return_val_if_fail(GNC_IS_ADDRESS(b), FALSE);
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-    if (safe_strcmp(a->addr1, b->addr1) != 0)
-    {
-        PWARN("address lines 1 differ: %s vs %s", a->addr1, b->addr1);
-        return FALSE;
-    }
-    if (safe_strcmp(a->addr2, b->addr2) != 0)
-    {
-        PWARN("address lines 2 differ: %s vs %s", a->addr2, b->addr1);
-        return FALSE;
-    }
-    if (safe_strcmp(a->addr3, b->addr3) != 0)
-    {
-        PWARN("address lines 3 differ: %s vs %s", a->addr3, b->addr3);
-        return FALSE;
-    }
-    if (safe_strcmp(a->addr4, b->addr4) != 0)
-    {
-        PWARN("address lines 4 differ: %s vs %s", a->addr4, b->addr4);
-        return FALSE;
-    }
-    if (safe_strcmp(a->phone, b->phone) != 0)
-    {
-        PWARN("phone numbers differ: %s vs %s", a->phone, b->phone);
-        return FALSE;
-    }
-    if (safe_strcmp(a->fax, b->fax) != 0)
-    {
-        PWARN("fax numbers differ: %s vs %s", a->fax, b->fax);
-        return FALSE;
-    }
-    if (safe_strcmp(a->email, b->email) != 0)
-    {
-        PWARN("email addresses differ: %s vs %s", a->email, b->email);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static QofObject GncAddressDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) GNC_ID_ADDRESS,
-    DI(.type_label        = ) "Address",
-    DI(.create            = ) (gpointer)qofAddressCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) NULL,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncAddressRegister (void)
-{
-    static QofParam params[] =
-    {
-
-        { ADDRESS_NAME,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName,  (QofSetterFunc)gncAddressSetName },
-        { ADDRESS_ONE,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr1, (QofSetterFunc)gncAddressSetAddr1 },
-        { ADDRESS_TWO,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr2, (QofSetterFunc)gncAddressSetAddr2 },
-        { ADDRESS_THREE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr3, (QofSetterFunc)gncAddressSetAddr3 },
-        { ADDRESS_FOUR,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr4, (QofSetterFunc)gncAddressSetAddr4 },
-        { ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, (QofSetterFunc)gncAddressSetPhone },
-        { ADDRESS_FAX,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax,   (QofSetterFunc)gncAddressSetFax },
-        { ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, (QofSetterFunc)gncAddressSetEmail },
-        { ADDRESS_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofAddressGetOwner, (QofSetterFunc)qofAddressSetOwner },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK,   (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    qof_class_register (GNC_ID_ADDRESS, (QofSortFunc)gncAddressCompare, params);
-    if (!qof_choice_add_class(GNC_ID_CUSTOMER, GNC_ID_ADDRESS, ADDRESS_OWNER))
-    {
-        return FALSE;
-    }
-
-    return qof_object_register(&GncAddressDesc);
-}

Deleted: gnucash/trunk/src/business/business-core/gncAddress.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncAddress.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,159 +0,0 @@
-/********************************************************************\
- * gncAddress.h -- an Address object                                *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Address
-
-An address belongs to another object, determined by the ::GncOwner.
-It is the owner that assigns a name and identifier to the address.
-In effect, an address is just a building - to make it useful to
-GnuCash, it needs to be tied to a person. After all, you cannot
-invoice a building, you invoice a person working / living in the
-building.
-
-QOF needs to handle all objects generically and to tie the address
-to an owner, QOF must be able to find each - as entities.
-
-This allows QOF to follow the hierarchy of objects without having
-to call any application-specific routines.
-
-To achieve this, new GncAddress routines have been added. An address
-is now created with a NULL parent and the parent set explicitly using
-the QOF object declaration. Whilst this adds functionality, it is
-important that a valid ::GncOwner entity is always set as a parent.
-This is an API issue - QOF will always set the parent provided that
-a suitable entity is passed to the qofAddressSetOwner routine. It is
-up to you to pass a suitable entity.
-
-    @{ */
-/** @file gncAddress.h
-    @brief an Address object
-    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
-    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
-*/
-
-#ifndef GNC_ADDRESS_H_
-#define GNC_ADDRESS_H_
-
-#include "qof.h"
-#ifdef GNUCASH_MAJOR_VERSION
-#include "gncBusiness.h"
-#endif
-
-#define GNC_ADDRESS_MODULE_NAME        "gncAddress"
-#define GNC_ID_ADDRESS GNC_ADDRESS_MODULE_NAME
-/** \struct GncAddress
-
- at param  QofInstance The address instance.
- at param	QofBook*	  Copy of the book pointer.
- at param	QofInstance* parent entity.
- at param	gboolean	dirty flag
- at param	char*	name of addressee
- at param	char*	first line of address
- at param	char*	second line of address
- at param	char*	third line of address
- at param	char*	fourth line of address
- at param	char*	phone number
- at param	char*	fax number
- at param	char*	email address
-*/
-typedef struct _gncAddress GncAddress;
-typedef struct _gncAddressClass GncAddressClass;
-
-/* --- type macros --- */
-#define GNC_TYPE_ADDRESS            (gnc_address_get_type ())
-#define GNC_ADDRESS(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ADDRESS, GncAddress))
-#define GNC_ADDRESS_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ADDRESS, GncAddressClass))
-#define GNC_IS_ADDRESS(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ADDRESS))
-#define GNC_IS_ADDRESS_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ADDRESS))
-#define GNC_ADDRESS_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ADDRESS, GncAddressClass))
-GType gnc_address_get_type(void);
-
-/** @name Create/Destroy functions
- @{ */
-GncAddress *gncAddressCreate (QofBook *book, QofInstance *parent);
-void gncAddressDestroy (GncAddress *addr);
-void gncAddressBeginEdit (GncAddress *addr);
-void gncAddressCommitEdit (GncAddress *addr);
-
-/** @} */
-
-/** @name Set functions
- @{ */
-
-void gncAddressSetName (GncAddress *addr, const char *name);
-void gncAddressSetAddr1 (GncAddress *addr, const char *addr1);
-void gncAddressSetAddr2 (GncAddress *addr, const char *addr2);
-void gncAddressSetAddr3 (GncAddress *addr, const char *addr3);
-void gncAddressSetAddr4 (GncAddress *addr, const char *addr4);
-void gncAddressSetPhone (GncAddress *addr, const char *phone);
-void gncAddressSetFax (GncAddress *addr, const char *fax);
-void gncAddressSetEmail (GncAddress *addr, const char *email);
-void gncAddressClearDirty (GncAddress *address);
-/** @} */
-
-/** @name Get Functions
- @{ */
-
-const char * gncAddressGetName (const GncAddress *addr);
-const char * gncAddressGetAddr1 (const GncAddress *addr);
-const char * gncAddressGetAddr2 (const GncAddress *addr);
-const char * gncAddressGetAddr3 (const GncAddress *addr);
-const char * gncAddressGetAddr4 (const GncAddress *addr);
-const char * gncAddressGetPhone (const GncAddress *addr);
-const char * gncAddressGetFax (const GncAddress *addr);
-const char * gncAddressGetEmail (const GncAddress *addr);
-/** @} */
-
-gboolean gncAddressIsDirty (const GncAddress *addr);
-
-/** \brief compare two addresses
-
-\return 0 if identical, -1 if a is empty or less than b
-and +1 if a is more than b or if b is empty.
-*/
-int gncAddressCompare (const GncAddress *a, const GncAddress *b);
-
-/** \brief Deeply compare two addresses
-
-\return TRUE if all fields match, FALSE otherwise
-*/
-gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b);
-
-#define ADDRESS_NAME    "name"
-#define ADDRESS_ONE		"number"
-#define ADDRESS_TWO		"street"
-#define ADDRESS_THREE   "locality"
-#define ADDRESS_FOUR	"city"
-#define ADDRESS_PHONE   "phone"
-#define ADDRESS_FAX     "fax"
-#define ADDRESS_EMAIL   "email"
-#define ADDRESS_OWNER   "owner"
-
-#endif /* GNC_ADDRESS_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncAddressP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddressP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncAddressP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,39 +0,0 @@
-/********************************************************************\
- * gncAddressP.h -- Private Business Interface:  Addresses          *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001, 2002 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_ADDRESSP_H_
-#define GNC_ADDRESSP_H_
-
-#include "gncAddress.h"
-
-gboolean gncAddressRegister (void);
-
-/** Make a copy of the address, setting the parent to 'new_parent' */
-GncAddress * gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book);
-
-
-#endif /* GNC_ADDRESSP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncBillTerm.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,941 +0,0 @@
-/********************************************************************\
- * gncBillTerm.c -- the Gnucash Billing Terms interface             *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-
-#include "gnc-engine.h"
-#include "gncBillTermP.h"
-
-struct _gncBillTerm
-{
-    QofInstance     inst;
-
-    /* 'visible' data fields directly manipulated by user */
-    char *          name;
-    char *          desc;
-    GncBillTermType type;
-    gint            due_days;
-    gint            disc_days;
-    gnc_numeric     discount;
-    gint            cutoff;
-
-    /* Internal management fields */
-    /* See src/doc/business.txt for an explanation of the following */
-    /* Code that handles this is *identical* to that in gncTaxTable */
-    gint64          refcount;
-    GncBillTerm *   parent;      /* if non-null, we are an immutable child */
-    GncBillTerm *   child;       /* if non-null, we have not changed */
-    gboolean        invisible;
-    GList *         children;    /* list of children for disconnection */
-};
-
-struct _gncBillTermClass
-{
-    QofInstanceClass parent_class;
-};
-
-struct _book_info
-{
-    GList *         terms;        /* visible terms */
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME        GNC_ID_BILLTERM
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncBillTermBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-AS_STRING_DEC(GncBillTermType, ENUM_TERMS_TYPE)
-FROM_STRING_DEC(GncBillTermType, ENUM_TERMS_TYPE)
-
-/* ============================================================== */
-/* Misc inline utilities */
-
-static inline void
-mark_term (GncBillTerm *term)
-{
-    qof_instance_set_dirty(&term->inst);
-    qof_event_gen (&term->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-static inline void maybe_resort_list (GncBillTerm *term)
-{
-    struct _book_info *bi;
-
-    if (term->parent || term->invisible) return;
-    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
-    bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
-}
-
-static inline void addObj (GncBillTerm *term)
-{
-    struct _book_info *bi;
-    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
-    bi->terms = g_list_insert_sorted (bi->terms, term,
-                                      (GCompareFunc)gncBillTermCompare);
-}
-
-static inline void remObj (GncBillTerm *term)
-{
-    struct _book_info *bi;
-    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
-    bi->terms = g_list_remove (bi->terms, term);
-}
-
-static inline void
-gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
-{
-    g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
-    table->children = g_list_prepend(table->children, child);
-}
-
-static inline void
-gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
-{
-    if (qof_instance_get_destroying(table)) return;
-    table->children = g_list_remove(table->children, child);
-}
-
-/* ============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncBillTerm, gnc_billterm, QOF_TYPE_INSTANCE);
-
-static void
-gnc_billterm_init(GncBillTerm* bt)
-{
-}
-
-static void
-gnc_billterm_dispose(GObject *btp)
-{
-    G_OBJECT_CLASS(gnc_billterm_parent_class)->dispose(btp);
-}
-
-static void
-gnc_billterm_finalize(GObject* btp)
-{
-    G_OBJECT_CLASS(gnc_billterm_parent_class)->finalize(btp);
-}
-
-static void
-gnc_billterm_get_property (GObject         *object,
-                           guint            prop_id,
-                           GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncBillTerm *bt;
-
-    g_return_if_fail(GNC_IS_BILLTERM(object));
-
-    bt = GNC_BILLTERM(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, bt->name);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_billterm_set_property (GObject         *object,
-                           guint            prop_id,
-                           const GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncBillTerm *bt;
-
-    g_return_if_fail(GNC_IS_BILLTERM(object));
-
-    bt = GNC_BILLTERM(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncBillTermSetName(bt, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    /* Bill term doesn't refer to anything except other billterms */
-    return NULL;
-}
-
-static void
-gnc_billterm_class_init (GncBillTermClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_billterm_dispose;
-    gobject_class->finalize = gnc_billterm_finalize;
-    gobject_class->set_property = gnc_billterm_set_property;
-    gobject_class->get_property = gnc_billterm_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = NULL;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "BillTerm Name",
-                          "The bill term name is an arbitrary string "
-                          "assigned by the user.  It is intended to "
-                          "a short, 10 to 30 character long string "
-                          "that is displayed by the GUI as the "
-                          "billterm mnemonic.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncBillTerm * gncBillTermCreate (QofBook *book)
-{
-    GncBillTerm *term;
-    if (!book) return NULL;
-
-    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
-    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
-    term->name = CACHE_INSERT ("");
-    term->desc = CACHE_INSERT ("");
-    term->discount = gnc_numeric_zero ();
-    addObj (term);
-    qof_event_gen (&term->inst,  QOF_EVENT_CREATE, NULL);
-    return term;
-}
-
-void gncBillTermDestroy (GncBillTerm *term)
-{
-    if (!term) return;
-    DEBUG("destroying bill term %s (%p)",
-          guid_to_string(qof_instance_get_guid(&term->inst)), term);
-    qof_instance_set_destroying(term, TRUE);
-    qof_instance_set_dirty (&term->inst);
-    gncBillTermCommitEdit (term);
-}
-
-static void gncBillTermFree (GncBillTerm *term)
-{
-    GncBillTerm *child;
-    GList *list;
-
-    if (!term) return;
-
-    qof_event_gen (&term->inst,  QOF_EVENT_DESTROY, NULL);
-    CACHE_REMOVE (term->name);
-    CACHE_REMOVE (term->desc);
-    remObj (term);
-
-    if (!qof_instance_get_destroying(term))
-        PERR("free a billterm without do_free set!");
-
-    /* disconnect from parent */
-    if (term->parent)
-        gncBillTermRemoveChild(term->parent, term);
-
-    /* disconnect from the children */
-    for (list = term->children; list; list = list->next)
-    {
-        child = list->data;
-        gncBillTermSetParent(child, NULL);
-    }
-    g_list_free(term->children);
-
-    /* qof_instance_release(&term->inst); */
-    g_object_unref (term);
-}
-
-GncBillTerm *
-gncCloneBillTerm (GncBillTerm *from, QofBook *book)
-{
-    GList *node;
-    GncBillTerm *term;
-
-    if (!book || !from) return NULL;
-
-    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
-    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&term->inst, &from->inst);
-
-    term->name = CACHE_INSERT (from->name);
-    term->desc = CACHE_INSERT (from->desc);
-    term->type = from->type;
-    term->due_days = from->due_days;
-    term->disc_days = from->disc_days;
-    term->discount = from->discount;
-    term->cutoff = from->cutoff;
-    term->invisible = from->invisible;
-
-    term->refcount = 0;
-
-    /* Make copies of parents and children. Note that this can be
-     * a recursive copy ... treat as doubly-linked list. */
-    if (from->child)
-    {
-        term->child = gncBillTermObtainTwin (from->child, book);
-        term->child->parent = term;
-    }
-    if (from->parent)
-    {
-        term->parent = gncBillTermObtainTwin (from->parent, book);
-        term->parent->child = term;
-    }
-    for (node = g_list_last(from->children); node; node = node->next)
-    {
-        GncBillTerm *btrm = node->data;
-        btrm = gncBillTermObtainTwin (btrm, book);
-        btrm->parent = term;
-        term->children = g_list_prepend(term->children, btrm);
-    }
-
-    addObj (term);
-    qof_event_gen (&term->inst, QOF_EVENT_CREATE, NULL);
-    return term;
-}
-
-GncBillTerm *
-gncBillTermObtainTwin (GncBillTerm *from, QofBook *book)
-{
-    GncBillTerm *term;
-    if (!from) return NULL;
-
-    term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!term)
-    {
-        term = gncCloneBillTerm (from, book);
-    }
-    return term;
-}
-
-/* ============================================================== */
-/* Set Functions */
-
-void gncBillTermSetName (GncBillTerm *term, const char *name)
-{
-    if (!term || !name) return;
-    SET_STR (term, term->name, name);
-    mark_term (term);
-    maybe_resort_list (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetDescription (GncBillTerm *term, const char *desc)
-{
-    if (!term || !desc) return;
-    SET_STR (term, term->desc, desc);
-    mark_term (term);
-    maybe_resort_list (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetType (GncBillTerm *term, GncBillTermType type)
-{
-    if (!term) return;
-    if (term->type == type) return;
-    gncBillTermBeginEdit (term);
-    term->type = type;
-    mark_term (term);
-    gncBillTermCommitEdit (term);
-}
-
-/** \brief Convert bill term types from text. */
-FROM_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
-
-static
-void qofBillTermSetType (GncBillTerm *term, const char *type_label)
-{
-    GncBillTermType type;
-
-    type = GncBillTermTypefromString(type_label);
-    gncBillTermSetType(term, type);
-}
-
-void gncBillTermSetDueDays (GncBillTerm *term, gint days)
-{
-    if (!term) return;
-    if (term->due_days == days) return;
-    gncBillTermBeginEdit (term);
-    term->due_days = days;
-    mark_term (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetDiscountDays (GncBillTerm *term, gint days)
-{
-    if (!term) return;
-    if (term->disc_days == days) return;
-    gncBillTermBeginEdit (term);
-    term->disc_days = days;
-    mark_term (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetDiscount (GncBillTerm *term, gnc_numeric discount)
-{
-    if (!term) return;
-    if (gnc_numeric_eq (term->discount, discount)) return;
-    gncBillTermBeginEdit (term);
-    term->discount = discount;
-    mark_term (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff)
-{
-    if (!term) return;
-    if (term->cutoff == cutoff) return;
-    gncBillTermBeginEdit (term);
-    term->cutoff = cutoff;
-    mark_term (term);
-    gncBillTermCommitEdit (term);
-}
-
-/* XXX this doesn't seem right. If the parent/child relationship
- * is a doubly-linked list, then there shouldn't be separate set-parent,
- * set-child routines, else misuse of the routines will goof up
- * relationships.  These ops should be atomic, I think.
- */
-void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent)
-{
-    if (!term) return;
-    gncBillTermBeginEdit (term);
-    if (term->parent)
-        gncBillTermRemoveChild(term->parent, term);
-    term->parent = parent;
-    if (parent)
-        gncBillTermAddChild(parent, term);
-    term->refcount = 0;
-    if ( parent != NULL )
-    {
-        gncBillTermMakeInvisible (term);
-    }
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child)
-{
-    if (!term) return;
-    gncBillTermBeginEdit (term);
-    term->child = child;
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermIncRef (GncBillTerm *term)
-{
-    if (!term) return;
-    if (term->parent || term->invisible) return;        /* children dont need refcounts */
-    gncBillTermBeginEdit (term);
-    term->refcount++;
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermDecRef (GncBillTerm *term)
-{
-    if (!term) return;
-    if (term->parent || term->invisible) return;        /* children dont need refcounts */
-    gncBillTermBeginEdit (term);
-    term->refcount--;
-    g_return_if_fail (term->refcount >= 0);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount)
-{
-    if (!term) return;
-    term->refcount = refcount;
-}
-
-void gncBillTermMakeInvisible (GncBillTerm *term)
-{
-    if (!term) return;
-    gncBillTermBeginEdit (term);
-    term->invisible = TRUE;
-    remObj (term);
-    gncBillTermCommitEdit (term);
-}
-
-void gncBillTermChanged (GncBillTerm *term)
-{
-    if (!term) return;
-    term->child = NULL;
-}
-
-void gncBillTermBeginEdit (GncBillTerm *term)
-{
-    qof_begin_edit(&term->inst);
-}
-
-static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("BillTerm QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void bill_free (QofInstance *inst)
-{
-    GncBillTerm *term = (GncBillTerm *) inst;
-    gncBillTermFree(term);
-}
-
-static void on_done (QofInstance *inst) {}
-
-void gncBillTermCommitEdit (GncBillTerm *term)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(term))) return;
-    qof_commit_edit_part2 (&term->inst, gncBillTermOnError,
-                           on_done, bill_free);
-}
-
-/* Get Functions */
-
-GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name)
-{
-    GList *list = gncBillTermGetTerms (book);
-
-    for ( ; list; list = list->next)
-    {
-        GncBillTerm *term = list->data;
-        if (!safe_strcmp (term->name, name))
-            return list->data;
-    }
-    return NULL;
-}
-
-GList * gncBillTermGetTerms (QofBook *book)
-{
-    struct _book_info *bi;
-    if (!book) return NULL;
-
-    bi = qof_book_get_data (book, _GNC_MOD_NAME);
-    return bi->terms;
-}
-
-const char *gncBillTermGetName (const GncBillTerm *term)
-{
-    if (!term) return NULL;
-    return term->name;
-}
-
-const char *gncBillTermGetDescription (const GncBillTerm *term)
-{
-    if (!term) return NULL;
-    return term->desc;
-}
-
-GncBillTermType gncBillTermGetType (const GncBillTerm *term)
-{
-    if (!term) return 0;
-    return term->type;
-}
-
-/** \brief Convert bill term types to text. */
-AS_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
-
-static
-const char* qofBillTermGetType (const GncBillTerm *term)
-{
-    if (!term)
-    {
-        return NULL;
-    }
-    return GncBillTermTypeasString(term->type);
-}
-
-gint gncBillTermGetDueDays (const GncBillTerm *term)
-{
-    if (!term) return 0;
-    return term->due_days;
-}
-
-gint gncBillTermGetDiscountDays (const GncBillTerm *term)
-{
-    if (!term) return 0;
-    return term->disc_days;
-}
-
-gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term)
-{
-    if (!term) return gnc_numeric_zero ();
-    return term->discount;
-}
-
-gint gncBillTermGetCutoff (const GncBillTerm *term)
-{
-    if (!term) return 0;
-    return term->cutoff;
-}
-
-static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
-{
-    GncBillTerm *t;
-
-    if (!term) return NULL;
-    t = gncBillTermCreate (qof_instance_get_book(term));
-
-    gncBillTermBeginEdit(t);
-
-    gncBillTermSetName (t, term->name);
-    gncBillTermSetDescription (t, term->desc);
-
-    t->type = term->type;
-    t->due_days = term->due_days;
-    t->disc_days = term->disc_days;
-    t->discount = term->discount;
-    t->cutoff = term->cutoff;
-
-    gncBillTermCommitEdit(t);
-
-    return t;
-}
-
-GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new)
-{
-    GncBillTerm *child = NULL;
-
-    if (!term) return NULL;
-    if (term->child) return term->child;
-    if (term->parent || term->invisible) return term;
-    if (make_new)
-    {
-        child = gncBillTermCopy (term);
-        gncBillTermSetChild (term, child);
-        gncBillTermSetParent (child, term);
-    }
-    return child;
-}
-
-GncBillTerm *gncBillTermGetParent (const GncBillTerm *term)
-{
-    if (!term) return NULL;
-    return term->parent;
-}
-
-gint64 gncBillTermGetRefcount (const GncBillTerm *term)
-{
-    if (!term) return 0;
-    return term->refcount;
-}
-
-gboolean gncBillTermGetInvisible (const GncBillTerm *term)
-{
-    if (!term) return FALSE;
-    return term->invisible;
-}
-
-int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b)
-{
-    int ret;
-
-    if (!a && !b) return 0;
-    if (!a) return -1;
-    if (!b) return 1;
-
-    ret = safe_strcmp (a->name, b->name);
-    if (ret) return ret;
-
-    return safe_strcmp (a->desc, b->desc);
-}
-
-gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_BILLTERM(a), FALSE);
-    g_return_val_if_fail(GNC_IS_BILLTERM(b), FALSE);
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("Names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->desc, b->desc) != 0)
-    {
-        PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
-        return FALSE;
-    }
-
-    if (a->type != b->type)
-    {
-        PWARN("Types differ");
-        return FALSE;
-    }
-
-    if (a->due_days != b->due_days)
-    {
-        PWARN("Due days differ: %d vs %d", a->due_days, b->due_days);
-        return FALSE;
-    }
-
-    if (a->disc_days != b->disc_days)
-    {
-        PWARN("Discount days differ: %d vs %d", a->disc_days, b->disc_days);
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->discount, b->discount))
-    {
-        PWARN("Discounts differ");
-        return FALSE;
-    }
-
-    if (a->cutoff != b->cutoff)
-    {
-        PWARN("Cutoffs differ: %d vs %d", a->cutoff, b->cutoff);
-        return FALSE;
-    }
-
-    if (a->invisible != b->invisible)
-    {
-        PWARN("Invisible flags differ");
-        return FALSE;
-    }
-
-//    gint64          refcount;
-//    GncBillTerm *   parent;      /* if non-null, we are an immutable child */
-//    GncBillTerm *   child;       /* if non-null, we have not changed */
-//    GList *         children;    /* list of children for disconnection */
-
-    return TRUE;
-}
-
-gboolean gncBillTermIsDirty (const GncBillTerm *term)
-{
-    if (!term) return FALSE;
-    return qof_instance_get_dirty_flag(term);
-}
-
-/********************************************************/
-/* functions to compute dates from Bill Terms           */
-
-#define SECS_PER_DAY 86400
-
-/* Based on the post date and a proximo type, compute the month and
- * year this is due.  The actual day is filled in below.
- *
- * A proximo billing term has multiple parameters:
- * * due day: day of the month the invoice/bill will be due
- * * cutoff: day of the month used to decide if the due date will be
- *           in the next month or in the month thereafter. This can be
- *           a negative number in which case the cutoff date is relative
- *           to the end of the month and counting backwards.
- *           Eg: cutoff = -3 would mean 25 in February or 28 in June
- *
- * How does it work:
- * Assume cutoff = 19 and due day = 20
- *
- * * Example 1 post date = 14-06-2010 (European date format)
- *   14 is less than the cutoff of 19, so the due date will be in the next
- *   month. Since the due day is set to 20, the due date will be
- *   20-07-2010
- *
- * * Example 2 post date = 22-06-2010 (European date format)
- *   22 is more than the cutoff of 19, so the due date will be in the month
- *   after next month. Since the due day is set to 20, the due date will be
- *   20-02-2010
- *
- */
-static void
-compute_monthyear (const GncBillTerm *term, Timespec post_date,
-                   int *month, int *year)
-{
-    int iday, imonth, iyear;
-    int cutoff = term->cutoff;
-
-    g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
-
-    gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
-
-    if (cutoff <= 0)
-        cutoff += gnc_timespec_last_mday (post_date);
-
-    if (iday <= cutoff)
-    {
-        /* We apply this to next month */
-        imonth++;
-    }
-    else
-    {
-        /* We apply to the following month */
-        imonth += 2;
-    }
-
-    if (imonth > 12)
-    {
-        iyear++;
-        imonth -= 12;
-    }
-
-    if (month) *month = imonth;
-    if (year) *year = iyear;
-}
-
-/* There are two types of billing terms:
- *
- * Type DAYS defines a due date to be a fixed number of days passed the post
- * date. This is a straightforward calculation.
- *
- * The other type PROXIMO defines the due date as a fixed day of the month
- * (like always the 15th of the month). The proximo algorithm determines which
- * month based on the cutoff day and the post date. See above for a more
- * detailed explanation of proximo.
- */
-
-static Timespec
-compute_time (const GncBillTerm *term, Timespec post_date, int days)
-{
-    Timespec res = post_date;
-    int day, month, year;
-
-    switch (term->type)
-    {
-    case GNC_TERM_TYPE_DAYS:
-        res.tv_sec += (SECS_PER_DAY * days);
-        break;
-    case GNC_TERM_TYPE_PROXIMO:
-        compute_monthyear (term, post_date, &month, &year);
-        day = gnc_date_my_last_mday (month, year);
-        if (days < day)
-            day = days;
-        res = gnc_dmy2timespec (day, month, year);
-        break;
-    }
-    return res;
-}
-
-Timespec
-gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date)
-{
-    Timespec res = post_date;
-    if (!term) return res;
-
-    return compute_time (term, post_date, term->due_days);
-}
-
-Timespec
-gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date)
-{
-    Timespec res = post_date;
-    if (!term) return res;
-
-    return compute_time (term, post_date, term->disc_days);
-}
-
-/* Package-Private functions */
-
-static void _gncBillTermCreate (QofBook *book)
-{
-    struct _book_info *bi;
-
-    if (!book) return;
-
-    bi = g_new0 (struct _book_info, 1);
-    qof_book_set_data (book, _GNC_MOD_NAME, bi);
-}
-
-static void _gncBillTermDestroy (QofBook *book)
-{
-    struct _book_info *bi;
-
-    if (!book) return;
-
-    bi = qof_book_get_data (book, _GNC_MOD_NAME);
-
-    g_list_free (bi->terms);
-    g_free (bi);
-}
-
-static QofObject gncBillTermDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Billing Term",
-    DI(.create            = ) (gpointer)gncBillTermCreate,
-    DI(.book_begin        = ) _gncBillTermCreate,
-    DI(.book_end          = ) _gncBillTermDestroy,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) NULL,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncBillTermRegister (void)
-{
-    static QofParam params[] =
-    {
-        { GNC_BILLTERM_NAME, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetName,			(QofSetterFunc)gncBillTermSetName },
-        { GNC_BILLTERM_DESC, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetDescription,		(QofSetterFunc)gncBillTermSetDescription },
-        { GNC_BILLTERM_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofBillTermGetType, (QofSetterFunc)qofBillTermSetType },
-        { GNC_BILLTERM_DUEDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDueDays, 		(QofSetterFunc)gncBillTermSetDueDays },
-        { GNC_BILLTERM_DISCDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDiscountDays,	(QofSetterFunc)gncBillTermSetDiscountDays },
-        { GNC_BILLTERM_DISCOUNT, 	QOF_TYPE_NUMERIC, (QofAccessFunc)gncBillTermGetDiscount,		(QofSetterFunc)gncBillTermSetDiscount },
-        { GNC_BILLTERM_CUTOFF, 		QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetCutoff, 			(QofSetterFunc)gncBillTermSetCutoff },
-        { GNC_BILLTERM_REFCOUNT, 	QOF_TYPE_INT64,   (QofAccessFunc)gncBillTermGetRefcount, 		NULL },
-        { QOF_PARAM_BOOK, 			QOF_ID_BOOK, 	  (QofAccessFunc)qof_instance_get_book, 		NULL },
-        { QOF_PARAM_GUID, 			QOF_TYPE_GUID, 	  (QofAccessFunc)qof_instance_get_guid, 		NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);
-
-    return qof_object_register (&gncBillTermDesc);
-}

Deleted: gnucash/trunk/src/business/business-core/gncBillTerm.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,161 +0,0 @@
-/********************************************************************\
- * gncBillTerm.h -- the Gnucash Billing Term interface              *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup BillTerm
-    @{ */
-/** @file gncBillTerm.h
-    @brief Billing Term interface
-    @author Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_BILLTERM_H_
-#define GNC_BILLTERM_H_
-
-typedef struct _gncBillTerm GncBillTerm;
-typedef struct _gncBillTermClass GncBillTermClass;
-
-#include "qof.h"
-#ifdef GNUCASH_MAJOR_VERSION
-#include "gncBusiness.h"
-#endif
-#define GNC_ID_BILLTERM       "gncBillTerm"
-
-/* --- type macros --- */
-#define GNC_TYPE_BILLTERM            (gnc_billterm_get_type ())
-#define GNC_BILLTERM(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_BILLTERM, GncBillTerm))
-#define GNC_BILLTERM_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_BILLTERM, GncBillTermClass))
-#define GNC_IS_BILLTERM(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_BILLTERM))
-#define GNC_IS_BILLTERM_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_BILLTERM))
-#define GNC_BILLTERM_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_BILLTERM, GncBillTermClass))
-GType gnc_billterm_get_type(void);
-
-/** @name BillTerm parameter names
- @{ */
-#define GNC_BILLTERM_NAME 		"name"
-#define GNC_BILLTERM_DESC 		"description"
-#define GNC_BILLTERM_DUEDAYS 	"number of days due"
-#define GNC_BILLTERM_DISCDAYS 	"number of discounted days"
-#define GNC_BILLTERM_CUTOFF 	"cut off"
-#define GNC_BILLTERM_TYPE 		"bill type"
-#define GNC_BILLTERM_DISCOUNT	"amount of discount"
-#define GNC_BILLTERM_REFCOUNT	"reference count"
-/** @} */
-
-/**
- * How to interpret the amount.
- * You can interpret it as a VALUE or a PERCENT.
- * ??? huh?
- * NOTE: This enum /depends/ on starting at value 1
- */
-#ifndef SWIG
-#define ENUM_TERMS_TYPE(_)  \
- _(GNC_TERM_TYPE_DAYS,=1) \
- _(GNC_TERM_TYPE_PROXIMO,)
-
-DEFINE_ENUM(GncBillTermType, ENUM_TERMS_TYPE)
-#else
-typedef enum
-{
-    GNC_TERM_TYPE_DAYS = 1,
-    GNC_TERM_TYPE_PROXIMO,
-} GncBillTermType;
-#endif
-
-/** @name Create/Destroy Functions
- @{ */
-GncBillTerm * gncBillTermCreate (QofBook *book);
-void gncBillTermDestroy (GncBillTerm *term);
-void gncBillTermIncRef (GncBillTerm *term);
-void gncBillTermDecRef (GncBillTerm *term);
-
-void gncBillTermChanged (GncBillTerm *term);
-void gncBillTermBeginEdit (GncBillTerm *term);
-void gncBillTermCommitEdit (GncBillTerm *term);
-/** @} */
-
-/** @name Set Functions
-@{
-*/
-void gncBillTermSetName (GncBillTerm *term, const char *name);
-void gncBillTermSetDescription (GncBillTerm *term, const char *name);
-void gncBillTermSetType (GncBillTerm *term, GncBillTermType type);
-void gncBillTermSetDueDays (GncBillTerm *term, gint days);
-void gncBillTermSetDiscountDays (GncBillTerm *term, gint days);
-void gncBillTermSetDiscount (GncBillTerm *term, gnc_numeric discount);
-void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff);
-
-/** @} */
-
-/** @name Get Functions
- @{ */
-/** Return a pointer to the instance gncBillTerm that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncBillTerm * gncBillTermLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncBillTerm * gncBillTermLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_BILLTERM, GncBillTerm);
-}
-
-GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name);
-GList * gncBillTermGetTerms (QofBook *book);
-
-const char *gncBillTermGetName (const GncBillTerm *term);
-const char *gncBillTermGetDescription (const GncBillTerm *term);
-GncBillTermType gncBillTermGetType (const GncBillTerm *term);
-gint gncBillTermGetDueDays (const GncBillTerm *term);
-gint gncBillTermGetDiscountDays (const GncBillTerm *term);
-gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term);
-gint gncBillTermGetCutoff (const GncBillTerm *term);
-
-gboolean gncBillTermIsDirty (const GncBillTerm *term);
-
-GncBillTerm *gncBillTermGetParent (const GncBillTerm *term);
-GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new);
-#define gncBillTermGetChild(t) gncBillTermReturnChild((t),FALSE)
-gint64 gncBillTermGetRefcount (const GncBillTerm *term);
-/** @} */
-
-int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b);
-gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b);
-
-/********************************************************/
-/* functions to compute dates from Bill Terms           */
-
-/* Compute the due date and discount dates from the post date */
-Timespec gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date);
-Timespec gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date);
-
-/* deprecated */
-#define gncBillTermGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x))
-
-#endif /* GNC_BILLTERM_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncBillTermP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTermP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBillTermP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,70 +0,0 @@
-/********************************************************************\
- * gncBillTermP.h -- the Gnucash Billing Term private interface     *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_BILLTERMP_H_
-#define GNC_BILLTERMP_H_
-
-#include "gncBillTerm.h"
-
-gboolean gncBillTermRegister (void);
-
-void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent);
-void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child);
-void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount);
-void gncBillTermMakeInvisible (GncBillTerm *term);
-
-gboolean gncBillTermGetInvisible (const GncBillTerm *term);
-
-/** The gncCloneBillTerm() routine makes a copy of the indicated
- *  bill term, placing it in the indicated book.  It copies
- *  the name, description, type, due-days, discount, etc.
- *  It also copies (as needed) both parents and children, so that
- *  the parent-child relationship is correctly mirrored in the
- *  clone.
- * XXX the refcount is mis-handled. This needs fixin....
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *);
-
-/** The gncBillTermObtainTwin() will find the 'twin' of the
- *  indicated bill term in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneBillTerm()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book);
-
-#define gncBillTermSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-
-#endif /* GNC_BILLTERMP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncBusGuile.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusGuile.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBusGuile.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,92 +0,0 @@
-/*
- * gncBusGuile.c -- Business Guile Helper Functions
- * Copyright (C) 2003 Derek Atkins
- * Author: Derek Atkins <warlord at 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
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-#include "config.h"
-
-#include "gncBusGuile.h"
-#include "engine-helpers.h"
-#include "swig-runtime.h"
-#include "guile-mappings.h"
-#define FUNC_NAME G_STRFUNC
-
-static swig_type_info *
-get_acct_type ()
-{
-    static swig_type_info * account_type = NULL;
-
-    if (!account_type)
-        account_type = SWIG_TypeQuery("_p_Account");
-
-    return account_type;
-}
-
-int gnc_account_value_pointer_p (SCM arg)
-{
-    swig_type_info * account_type = get_acct_type();
-
-    return (scm_is_pair (arg) &&
-            SWIG_IsPointerOfType(SCM_CAR (arg), account_type) &&
-            gnc_numeric_p (SCM_CDR (arg)));
-}
-
-GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg)
-{
-    GncAccountValue *res;
-    Account *acc = NULL;
-    gnc_numeric value;
-    swig_type_info * account_type = get_acct_type();
-    SCM val;
-
-    /* Get the account */
-    val = SCM_CAR (valuearg);
-    if (!SWIG_IsPointerOfType (val, account_type))
-        return NULL;
-
-    acc = SWIG_MustGetPtr(val, account_type, 1, 0);
-
-    /* Get the value */
-    val = SCM_CDR (valuearg);
-    value = gnc_scm_to_numeric (val);
-
-    /* Build and return the object */
-    res = g_new0 (GncAccountValue, 1);
-    res->account = acc;
-    res->value = value;
-    return res;
-}
-
-SCM gnc_account_value_ptr_to_scm (GncAccountValue *av)
-{
-    swig_type_info * account_type = get_acct_type();
-    gnc_commodity * com;
-    gnc_numeric val;
-
-    if (!av) return SCM_BOOL_F;
-
-    com = xaccAccountGetCommodity (av->account);
-    val = gnc_numeric_convert (av->value, gnc_commodity_get_fraction (com),
-                               GNC_RND_ROUND);
-
-    return scm_cons (SWIG_NewPointerObj(av->account, account_type, 0),
-                     gnc_numeric_to_scm (val));
-}

Deleted: gnucash/trunk/src/business/business-core/gncBusGuile.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusGuile.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBusGuile.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,34 +0,0 @@
-/*
- * gncBusGuile.h -- Business Guile Helper Functions
- * Copyright (C) 2003 Derek Atkins
- * Author: Derek Atkins <warlord at 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
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-#ifndef GNC_BUSINESS_GUILE_H_
-#define GNC_BUSINESS_GUILE_H_
-
-#include <gncTaxTable.h>	/* for GncAccountValue */
-#include <libguile.h>
-
-int gnc_account_value_pointer_p (SCM arg);
-GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg);
-SCM gnc_account_value_ptr_to_scm (GncAccountValue *);
-
-#endif /* GNC_BUSINESS_GUILE_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncBusPeriod.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusPeriod.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBusPeriod.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,81 +0,0 @@
-
-/*
-XXX TODO:
--- contemplate a per-collection (per type) edit/commmit-edit,
-   clone, dirty, etc. functions some more ...
-
--- turn clone into a generic object callback, so that
-   the ObtainTwin could be qof_instance_obtain_twin,
-   a generic function. (right now its copied everywhere)
-
--- contemplate copy-on-write, and the true need for cloning,
-   and how to avoid excess cloning for the SQL backend.
-
--- billterm and taxtables are incompletely cloned, not sure
-   what to do with refcount, ask warlord, need to explore.
-
--- The following business objects have an id/name/desc/active
-   this could be abstracted into an common object.
-   vendor (customer)
-   bill term (but bill terms doesn't have id or active)
-   job
-
--- gncVendor should be a base class to gncCustomer (they're
-   identical, but customer adds more stuff).
-
-   Employee could be base class for vendor, its got some of the
-   things (name, addr, active, currency)
-
--- TaxTable and BillTerm have common parent/child code.
-   this could be abstracted into common code.
-
-=======
--- finish clone of invoice, entry,
-
-
--- jobs in the vendor job list that are no longer active should
-   be kept back in old book, removed from new book??
-   ditto jobs in the customer list ??
-
--- closed orders can be removed from new book ?
-*/
-
-
-
-#include "gncBusiness.h"
-
-/** Copy all customers from one book to another.  Do this
- *  by iterating over all existing customers in the src book,
- *  and creating a clone for the dest book. */
-
-void
-gncCustomerCopyAll (QofBook *dest_book, QofBook *src_book)
-{
-
-}
-
-static void
-bill_term_copy_helper (gpointer object, gpointer user_data)
-{
-    QofBook *dest_book = user_data;
-    gncBillTerm *src_term = object;
-    gncCloneBillTerm (src_term, dest_book);
-}
-
-void
-gncBillTermCopyAll (QofBook *dest_book, QofBook *src_book)
-{
-    qof_object_foreach (GNC_BILLTERM_MODULE_NAME,
-                        src_book, bill_term_copy_helper, dest_book);
-}
-
-
-
-partition (QofBook *dest_book, QofBook *src_book)
-{
-
-    /* Copy all bill terms first, since the CustomerCopy expects
-     * these to be in place already. */
-    /* XXX not strictly needed, the customer can pull their own .. ? */
-    gncBillTermCopyAll (dest_book, src_book);
-}

Deleted: gnucash/trunk/src/business/business-core/gncBusiness.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusiness.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBusiness.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,57 +0,0 @@
-/*
- * gncBusiness.c -- Business helper functions
- * Copyright (C) 2002 Derek Atkins
- * Author: Derek Atkins <warlord at 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
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-#include "config.h"
-
-#include "gncBusiness.h"
-
-#include <glib.h>
-
-#include "gncAddressP.h"
-#include "gncBillTermP.h"
-#include "gncCustomerP.h"
-#include "gncEmployeeP.h"
-#include "gncEntryP.h"
-#include "gncInvoiceP.h"
-#include "gncJobP.h"
-#include "gncOrderP.h"
-#include "gncOwnerP.h"
-#include "gncTaxTableP.h"
-#include "gncVendorP.h"
-
-void
-gnc_module_init_business_core_init(void)
-{
-    /* initialize known types */
-    gncInvoiceRegister ();
-    gncJobRegister ();
-    gncBillTermRegister ();
-    gncCustomerRegister ();
-    gncAddressRegister ();
-    gncEmployeeRegister ();
-    gncEntryRegister ();
-    gncOrderRegister ();
-    gncOwnerRegister ();
-    gncTaxTableRegister ();
-    gncVendorRegister ();
-}

Deleted: gnucash/trunk/src/business/business-core/gncBusiness.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusiness.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncBusiness.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,63 +0,0 @@
-/* gncBusiness.h -- Business Helper Functions
- *
- * 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
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-/** @addtogroup Engine
-    @{ */
-/** @addtogroup Business
-    The Business Engine provides a set of structures for
-    that provide small-business accounting features.
-    @{ */
-
-/** @file gncBusiness.h -- Business Helper Functions
- *  @author Copyright (C) 2002 Derek Atkins
- *  @author Derek Atkins <warlord at MIT.EDU>
- */
-
-/** @} */
-/** @} */
-#ifndef GNC_BUSINESS_H_
-#define GNC_BUSINESS_H_
-
-
-/* @deprecated backwards-compat definitions */
-#define GNC_BILLTERM_MODULE_NAME GNC_ID_BILLTERM
-#define GNC_CUSTOMER_MODULE_NAME GNC_ID_CUSTOMER
-#define GNC_EMPLOYEE_MODULE_NAME GNC_ID_EMPLOYEE
-#define GNC_ENTRY_MODULE_NAME    GNC_ID_ENTRY
-#define GNC_INVOICE_MODULE_NAME  GNC_ID_INVOICE
-#define GNC_JOB_MODULE_NAME      GNC_ID_JOB
-#define GNC_ORDER_MODULE_NAME    GNC_ID_ORDER
-#define GNC_OWNER_MODULE_NAME    GNC_ID_OWNER
-#define GNC_TAXTABLE_MODULE_NAME GNC_ID_TAXTABLE
-#define GNC_VENDOR_MODULE_NAME   GNC_ID_VENDOR
-
-void
-gnc_module_init_business_core_init(void);
-
-#ifndef DI
-# ifdef _MSC_VER
-/* MSVC compiler doesn't have C99 "designated initializers"
- * so we wrap them in a macro that is empty on MSVC. */
-#  define DI(x) /* */
-# else
-#  define DI(x) x
-# endif
-#endif
-
-#endif /* GNC_BUSINESS_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,933 +0,0 @@
-/********************************************************************\
- * gncCustomer.c -- the Core Customer Interface                     *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001,2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "gnc-commodity.h"
-
-#include "gncAddressP.h"
-#include "gncBillTermP.h"
-#include "gncInvoice.h"
-#ifdef GNUCASH_MAJOR_VERSION
-#include "gncBusiness.h"
-#endif
-
-#include "gncCustomer.h"
-#include "gncCustomerP.h"
-#include "gncJobP.h"
-#include "gncTaxTableP.h"
-
-static gint gs_address_event_handler_id = 0;
-static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                                      gpointer user_data, gpointer event_data);
-
-struct _gncCustomer
-{
-    QofInstance     inst;
-
-    /* The following fields are identical to 'vendor' */
-    char *          id;
-    char *          name;
-    char *          notes;
-    GncBillTerm *   terms;
-    GncAddress *    addr;
-    gnc_commodity * currency;
-    GncTaxTable*    taxtable;
-    gboolean        taxtable_override;
-    GncTaxIncluded  taxincluded;
-    gboolean        active;
-    GList *         jobs;
-
-    /* The following fields are unique to 'customer' */
-    gnc_numeric     credit;
-    gnc_numeric     discount;
-    GncAddress *    shipaddr;
-};
-
-struct _gncCustomerClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME        GNC_ID_CUSTOMER
-
-/* ============================================================== */
-/* misc inline funcs */
-
-G_INLINE_FUNC void mark_customer (GncCustomer *customer);
-void mark_customer (GncCustomer *customer)
-{
-    qof_instance_set_dirty(&customer->inst);
-    qof_event_gen (&customer->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* ============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncCustomer, gnc_customer, QOF_TYPE_INSTANCE);
-
-static void
-gnc_customer_init(GncCustomer* cust)
-{
-}
-
-static void
-gnc_customer_dispose(GObject *custp)
-{
-    G_OBJECT_CLASS(gnc_customer_parent_class)->dispose(custp);
-}
-
-static void
-gnc_customer_finalize(GObject* custp)
-{
-    G_OBJECT_CLASS(gnc_customer_parent_class)->finalize(custp);
-}
-
-static void
-gnc_customer_get_property (GObject         *object,
-                           guint            prop_id,
-                           GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncCustomer *cust;
-
-    g_return_if_fail(GNC_IS_CUSTOMER(object));
-
-    cust = GNC_CUSTOMER(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, cust->name);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_customer_set_property (GObject         *object,
-                           guint            prop_id,
-                           const GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncCustomer *cust;
-
-    g_return_if_fail(GNC_IS_CUSTOMER(object));
-
-    cust = GNC_CUSTOMER(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncCustomerSetName(cust, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Return display name for this object */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncCustomer* cust;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
-
-    cust = GNC_CUSTOMER(inst);
-    /* XXX internationalization of "Customer" */
-    return g_strdup_printf("Customer %s", cust->name);
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncCustomer* cust;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
-
-    cust = GNC_CUSTOMER(inst);
-
-    if (GNC_IS_BILLTERM(ref))
-    {
-        return (cust->terms == GNC_BILLTERM(ref));
-    }
-    else if (GNC_IS_TAXTABLE(ref))
-    {
-        return (cust->taxtable == GNC_TAXTABLE(ref));
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_customer_class_init (GncCustomerClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_customer_dispose;
-    gobject_class->finalize = gnc_customer_finalize;
-    gobject_class->set_property = gnc_customer_set_property;
-    gobject_class->get_property = gnc_customer_get_property;
-
-    qof_class->get_display_name = impl_get_display_name;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "Customer Name",
-                          "The customer is an arbitrary string "
-                          "assigned by the user which provides the "
-                          "customer name.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncCustomer *gncCustomerCreate (QofBook *book)
-{
-    GncCustomer *cust;
-
-    if (!book) return NULL;
-
-    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
-    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
-
-    cust->id = CACHE_INSERT ("");
-    cust->name = CACHE_INSERT ("");
-    cust->notes = CACHE_INSERT ("");
-    cust->addr = gncAddressCreate (book, &cust->inst);
-    cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
-    cust->active = TRUE;
-    cust->jobs = NULL;
-
-    cust->discount = gnc_numeric_zero();
-    cust->credit = gnc_numeric_zero();
-    cust->shipaddr = gncAddressCreate (book, &cust->inst);
-
-    if (gs_address_event_handler_id == 0)
-    {
-        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
-    }
-
-    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
-
-    return cust;
-}
-
-/** Create a copy of a customer, placing the copy into a new book. */
-GncCustomer *
-gncCloneCustomer (GncCustomer *from, QofBook *book)
-{
-    GList *node;
-    GncCustomer *cust;
-
-    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
-
-    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&cust->inst, &from->inst);
-
-    cust->id = CACHE_INSERT (from->id);
-    cust->name = CACHE_INSERT (from->name);
-    cust->notes = CACHE_INSERT (from->notes);
-    cust->discount = from->discount;
-    cust->credit = from->credit;
-    cust->taxincluded = from->taxincluded;
-    cust->active = from->active;
-    cust->taxtable_override = from->taxtable_override;
-
-    cust->addr = gncCloneAddress (from->addr, &cust->inst, book);
-    cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst, book);
-
-    /* Find the matching currency in the new book, assumes
-     * currency has already been copied into new book. */
-    cust->currency = gnc_commodity_obtain_twin (from->currency, book);
-
-    /* Find the matching bill term, tax table in the new book */
-    cust->terms = gncBillTermObtainTwin(from->terms, book);
-    cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
-
-    for (node = g_list_last(cust->jobs); node; node = node->next)
-    {
-        GncJob *job = node->data;
-        job = gncJobObtainTwin (job, book);
-        cust->jobs = g_list_prepend(cust->jobs, job);
-    }
-
-    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
-
-    return cust;
-}
-
-void gncCustomerDestroy (GncCustomer *cust)
-{
-    if (!cust) return;
-    qof_instance_set_destroying(cust, TRUE);
-    qof_instance_set_dirty (&cust->inst);
-    gncCustomerCommitEdit (cust);
-}
-
-static void gncCustomerFree (GncCustomer *cust)
-{
-    if (!cust) return;
-
-    qof_event_gen (&cust->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (cust->id);
-    CACHE_REMOVE (cust->name);
-    CACHE_REMOVE (cust->notes);
-    gncAddressBeginEdit (cust->addr);
-    gncAddressDestroy (cust->addr);
-    gncAddressBeginEdit (cust->shipaddr);
-    gncAddressDestroy (cust->shipaddr);
-    g_list_free (cust->jobs);
-
-    if (cust->terms)
-        gncBillTermDecRef (cust->terms);
-    if (cust->taxtable)
-    {
-        gncTaxTableDecRef (cust->taxtable);
-    }
-
-    /* qof_instance_release (&cust->inst); */
-    g_object_unref (cust);
-}
-
-GncCustomer *
-gncCustomerObtainTwin (GncCustomer *from, QofBook *book)
-{
-    GncCustomer *cust;
-    if (!from) return NULL;
-
-    cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!cust)
-    {
-        cust = gncCloneCustomer (from, book);
-    }
-    return cust;
-}
-
-/* ============================================================== */
-/* Set Functions */
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncCustomerBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-void gncCustomerSetID (GncCustomer *cust, const char *id)
-{
-    if (!cust) return;
-    if (!id) return;
-    SET_STR(cust, cust->id, id);
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetName (GncCustomer *cust, const char *name)
-{
-    if (!cust) return;
-    if (!name) return;
-    SET_STR(cust, cust->name, name);
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetNotes (GncCustomer *cust, const char *notes)
-{
-    if (!cust) return;
-    if (!notes) return;
-    SET_STR(cust, cust->notes, notes);
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetTerms (GncCustomer *cust, GncBillTerm *terms)
-{
-    if (!cust) return;
-    if (cust->terms == terms) return;
-
-    gncCustomerBeginEdit (cust);
-    if (cust->terms)
-        gncBillTermDecRef (cust->terms);
-    cust->terms = terms;
-    if (cust->terms)
-        gncBillTermIncRef (cust->terms);
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetTaxIncluded (GncCustomer *cust, GncTaxIncluded taxincl)
-{
-    if (!cust) return;
-    if (taxincl == cust->taxincluded) return;
-    gncCustomerBeginEdit (cust);
-    cust->taxincluded = taxincl;
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetActive (GncCustomer *cust, gboolean active)
-{
-    if (!cust) return;
-    if (active == cust->active) return;
-    gncCustomerBeginEdit (cust);
-    cust->active = active;
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetDiscount (GncCustomer *cust, gnc_numeric discount)
-{
-    if (!cust) return;
-    if (gnc_numeric_equal (discount, cust->discount)) return;
-    gncCustomerBeginEdit (cust);
-    cust->discount = discount;
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetCredit (GncCustomer *cust, gnc_numeric credit)
-{
-    if (!cust) return;
-    if (gnc_numeric_equal (credit, cust->credit)) return;
-    gncCustomerBeginEdit (cust);
-    cust->credit = credit;
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetCurrency (GncCustomer *cust, gnc_commodity *currency)
-{
-    if (!cust || !currency) return;
-    if (cust->currency && gnc_commodity_equal (cust->currency, currency)) return;
-    gncCustomerBeginEdit (cust);
-    cust->currency = currency;
-    mark_customer (cust);
-    gncCustomerCommitEdit (cust);
-}
-
-void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override)
-{
-    if (!customer) return;
-    if (customer->taxtable_override == override) return;
-    gncCustomerBeginEdit (customer);
-    customer->taxtable_override = override;
-    mark_customer (customer);
-    gncCustomerCommitEdit (customer);
-}
-
-void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table)
-{
-    if (!customer) return;
-    if (customer->taxtable == table) return;
-
-    gncCustomerBeginEdit (customer);
-    if (customer->taxtable)
-        gncTaxTableDecRef (customer->taxtable);
-    if (table)
-        gncTaxTableIncRef (table);
-    customer->taxtable = table;
-    mark_customer (customer);
-    gncCustomerCommitEdit (customer);
-}
-
-/* Note that JobList changes do not affect the "dirtiness" of the customer */
-void gncCustomerAddJob (GncCustomer *cust, GncJob *job)
-{
-    if (!cust) return;
-    if (!job) return;
-
-    if (g_list_index(cust->jobs, job) == -1)
-        cust->jobs = g_list_insert_sorted (cust->jobs, job,
-                                           (GCompareFunc)gncJobCompare);
-
-    qof_event_gen (&cust->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
-{
-    GList *node;
-
-    if (!cust) return;
-    if (!job) return;
-
-    node = g_list_find (cust->jobs, job);
-    if (!node)
-    {
-        /*    PERR ("split not in account"); */
-    }
-    else
-    {
-        cust->jobs = g_list_remove_link (cust->jobs, node);
-        g_list_free_1 (node);
-    }
-    qof_event_gen (&cust->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-void gncCustomerBeginEdit (GncCustomer *cust)
-{
-    qof_begin_edit (&cust->inst);
-}
-
-static void gncCustomerOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("Customer QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncCustomerOnDone (QofInstance *inst)
-{
-    GncCustomer *cust = (GncCustomer *) inst;
-    gncAddressClearDirty (cust->addr);
-    gncAddressClearDirty (cust->shipaddr);
-}
-
-static void cust_free (QofInstance *inst)
-{
-    GncCustomer *cust = (GncCustomer *) inst;
-    gncCustomerFree (cust);
-}
-
-void gncCustomerCommitEdit (GncCustomer *cust)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(cust))) return;
-    qof_commit_edit_part2 (&cust->inst, gncCustomerOnError,
-                           gncCustomerOnDone, cust_free);
-}
-
-/* ============================================================== */
-/* Get Functions */
-
-const char * gncCustomerGetID (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->id;
-}
-
-const char * gncCustomerGetName (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->name;
-}
-
-GncAddress * gncCustomerGetAddr (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->addr;
-}
-
-static void
-qofCustomerSetAddr (GncCustomer *cust, QofInstance *addr_ent)
-{
-    GncAddress *addr;
-
-    if (!cust || !addr_ent)
-    {
-        return;
-    }
-    addr = (GncAddress*)addr_ent;
-    if (addr == cust->addr)
-    {
-        return;
-    }
-    if (cust->addr != NULL)
-    {
-        gncAddressBeginEdit(cust->addr);
-        gncAddressDestroy(cust->addr);
-    }
-    gncCustomerBeginEdit(cust);
-    cust->addr = addr;
-    gncCustomerCommitEdit(cust);
-}
-
-static void
-qofCustomerSetShipAddr (GncCustomer *cust, QofInstance *ship_addr_ent)
-{
-    GncAddress *ship_addr;
-
-    if (!cust || !ship_addr_ent)
-    {
-        return;
-    }
-    ship_addr = (GncAddress*)ship_addr_ent;
-    if (ship_addr == cust->shipaddr)
-    {
-        return;
-    }
-    if (cust->shipaddr != NULL)
-    {
-        gncAddressBeginEdit(cust->shipaddr);
-        gncAddressDestroy(cust->shipaddr);
-    }
-    gncCustomerBeginEdit(cust);
-    cust->shipaddr = ship_addr;
-    gncCustomerCommitEdit(cust);
-}
-
-GncAddress * gncCustomerGetShipAddr (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->shipaddr;
-}
-
-const char * gncCustomerGetNotes (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->notes;
-}
-
-GncBillTerm * gncCustomerGetTerms (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->terms;
-}
-
-GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *cust)
-{
-    if (!cust) return GNC_TAXINCLUDED_USEGLOBAL;
-    return cust->taxincluded;
-}
-
-gnc_commodity * gncCustomerGetCurrency (const GncCustomer *cust)
-{
-    if (!cust) return NULL;
-    return cust->currency;
-}
-
-gboolean gncCustomerGetActive (const GncCustomer *cust)
-{
-    if (!cust) return FALSE;
-    return cust->active;
-}
-
-gnc_numeric gncCustomerGetDiscount (const GncCustomer *cust)
-{
-    if (!cust) return gnc_numeric_zero();
-    return cust->discount;
-}
-
-gnc_numeric gncCustomerGetCredit (const GncCustomer *cust)
-{
-    if (!cust) return gnc_numeric_zero();
-    return cust->credit;
-}
-
-gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer)
-{
-    if (!customer) return FALSE;
-    return customer->taxtable_override;
-}
-
-GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer)
-{
-    if (!customer) return NULL;
-    return customer->taxtable;
-}
-
-GList * gncCustomerGetJoblist (const GncCustomer *cust, gboolean show_all)
-{
-    if (!cust) return NULL;
-
-    if (show_all)
-    {
-        return (g_list_copy (cust->jobs));
-    }
-    else
-    {
-        GList *list = NULL, *iterator;
-        for (iterator = cust->jobs; iterator; iterator = iterator->next)
-        {
-            GncJob *j = iterator->data;
-            if (gncJobGetActive (j))
-                list = g_list_append (list, j);
-        }
-        return list;
-    }
-}
-
-gboolean gncCustomerIsDirty (GncCustomer *cust)
-{
-    if (!cust) return FALSE;
-    return (qof_instance_is_dirty(&cust->inst) ||
-            gncAddressIsDirty (cust->addr) ||
-            gncAddressIsDirty (cust->shipaddr));
-}
-
-/* Other functions */
-
-int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    return(strcmp(a->name, b->name));
-}
-
-gboolean
-gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_CUSTOMER(a), FALSE);
-    g_return_val_if_fail(GNC_IS_CUSTOMER(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("Names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->notes, b->notes) != 0)
-    {
-        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
-        return FALSE;
-    }
-
-    if (!gncBillTermEqual(a->terms, b->terms))
-    {
-        PWARN("Bill terms differ");
-        return FALSE;
-    }
-
-    if (!gnc_commodity_equal(a->currency, b->currency))
-    {
-        PWARN("currencies differ");
-        return FALSE;
-    }
-
-    if (!gncTaxTableEqual(a->taxtable, b->taxtable))
-    {
-        PWARN("tax tables differ");
-        return FALSE;
-    }
-
-    if (a->taxtable_override != b->taxtable_override)
-    {
-        PWARN("Tax table override flags differ");
-        return FALSE;
-    }
-
-    if (a->taxincluded != b->taxincluded)
-    {
-        PWARN("Tax included flags differ");
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-    if (!gncAddressEqual(a->addr, b->addr))
-    {
-        PWARN("addresses differ");
-        return FALSE;
-    }
-    if (!gncAddressEqual(a->shipaddr, b->shipaddr))
-    {
-        PWARN("addresses differ");
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->credit, b->credit))
-    {
-        PWARN("Credit amounts differ");
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->discount, b->discount))
-    {
-        PWARN("Discount amounts differ");
-        return FALSE;
-    }
-
-    /* FIXME: Need to check jobs list
-    GList *         jobs;
-    */
-
-    return TRUE;
-}
-
-/**
- * Listens for MODIFY events from addresses.   If the address belongs to a customer,
- * mark the customer as dirty.
- *
- * @param entity Entity for the event
- * @param event_type Event type
- * @param user_data User data registered with the handler
- * @param event_data Event data passed with the event.
- */
-static void
-listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                          gpointer user_data, gpointer event_data)
-{
-    GncCustomer* cust;
-
-    if ((event_type & QOF_EVENT_MODIFY) == 0)
-    {
-        return;
-    }
-    if (!GNC_IS_ADDRESS(entity))
-    {
-        return;
-    }
-    if (!GNC_IS_CUSTOMER(event_data))
-    {
-        return;
-    }
-    cust = GNC_CUSTOMER(event_data);
-    gncCustomerBeginEdit(cust);
-    mark_customer(cust);
-    gncCustomerCommitEdit(cust);
-}
-/* ============================================================== */
-/* Package-Private functions */
-static const char * _gncCustomerPrintable (gpointer item)
-{
-//  GncCustomer *c = item;
-    if (!item) return "failed";
-    return gncCustomerGetName((GncCustomer*)item);
-}
-
-static QofObject gncCustomerDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Customer",
-    DI(.create            = ) (gpointer)gncCustomerCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) (const char * (*)(gpointer))gncCustomerGetName,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncCustomerRegister (void)
-{
-    static QofParam params[] =
-    {
-        { CUSTOMER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetID, (QofSetterFunc)gncCustomerSetID },
-        { CUSTOMER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetName, (QofSetterFunc)gncCustomerSetName },
-        { CUSTOMER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetNotes, (QofSetterFunc)gncCustomerSetNotes },
-        {
-            CUSTOMER_DISCOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc)gncCustomerGetDiscount,
-            (QofSetterFunc)gncCustomerSetDiscount
-        },
-        {
-            CUSTOMER_CREDIT, QOF_TYPE_NUMERIC, (QofAccessFunc)gncCustomerGetCredit,
-            (QofSetterFunc)gncCustomerSetCredit
-        },
-        { CUSTOMER_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncCustomerGetAddr, (QofSetterFunc)qofCustomerSetAddr },
-        { CUSTOMER_SHIPADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncCustomerGetShipAddr, (QofSetterFunc)qofCustomerSetShipAddr },
-        {
-            CUSTOMER_TT_OVER, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetTaxTableOverride,
-            (QofSetterFunc)gncCustomerSetTaxTableOverride
-        },
-        { CUSTOMER_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncCustomerGetTerms, (QofSetterFunc)gncCustomerSetTerms },
-        { CUSTOMER_SLOTS, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive, (QofSetterFunc)gncCustomerSetActive },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_CUSTOMER, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_CUSTOMER, JOB_OWNER))
-    {
-        return FALSE;
-    }
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare, params);
-    if (!qof_choice_create(GNC_ID_CUSTOMER))
-    {
-        return FALSE;
-    }
-    /* temp */
-    _gncCustomerPrintable(NULL);
-    return qof_object_register (&gncCustomerDesc);
-}
-
-gint64 gncCustomerNextID (QofBook *book)
-{
-    return qof_book_get_counter (book, _GNC_MOD_NAME);
-}

Deleted: gnucash/trunk/src/business/business-core/gncCustomer.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncCustomer.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,166 +0,0 @@
-/********************************************************************\
- * gncCustomer.h -- the Core Customer Interface                     *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Customer
-    @{ */
-/** @file gncCustomer.h
-    @brief Core Customer Interface
-    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_CUSTOMER_H_
-#define GNC_CUSTOMER_H_
-
-/** @struct GncCustomer
-
-credit, discount and shipaddr are unique to GncCustomer\n
-id, name, notes, terms, addr, currency, taxtable, taxtable_override
-taxincluded, active and jobs are identical to ::GncVendor.
-
- at param	QofInstance     inst;
- at param	char *          id;
- at param	char *          name;
- at param	char *          notes;
- at param	GncBillTerm *   terms;
- at param	GncAddress *    addr;
- at param	gnc_commodity * currency;
- at param	GncTaxTable*    taxtable;
- at param	gboolean        taxtable_override;
- at param	GncTaxIncluded  taxincluded;
- at param	gboolean        active;
- at param	GList *         jobs;
- at param	gnc_numeric     credit;
- at param	gnc_numeric     discount;
- at param	GncAddress *    shipaddr;
-
-*/
-typedef struct _gncCustomer GncCustomer;
-typedef struct _gncCustomerClass GncCustomerClass;
-
-#include "gncAddress.h"
-#include "gncBillTerm.h"
-#include "gncTaxTable.h"
-#include "gncJob.h"
-
-#define GNC_ID_CUSTOMER       "gncCustomer"
-
-/* --- type macros --- */
-#define GNC_TYPE_CUSTOMER            (gnc_customer_get_type ())
-#define GNC_CUSTOMER(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_CUSTOMER, GncCustomer))
-#define GNC_CUSTOMER_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_CUSTOMER, GncCustomerClass))
-#define GNC_IS_CUSTOMER(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_CUSTOMER))
-#define GNC_IS_CUSTOMER_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_CUSTOMER))
-#define GNC_CUSTOMER_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_CUSTOMER, GncCustomerClass))
-GType gnc_customer_get_type(void);
-
-/** @name Create/Destroy Functions
- @{ */
-GncCustomer *gncCustomerCreate (QofBook *book);
-void gncCustomerDestroy (GncCustomer *customer);
-void gncCustomerBeginEdit (GncCustomer *customer);
-void gncCustomerCommitEdit (GncCustomer *customer);
-/** @} */
-
-/** @name Set Functions
- @{ */
-
-void gncCustomerSetID (GncCustomer *customer, const char *id);
-void gncCustomerSetName (GncCustomer *customer, const char *name);
-void gncCustomerSetNotes (GncCustomer *customer, const char *notes);
-void gncCustomerSetTerms (GncCustomer *customer, GncBillTerm *term);
-void gncCustomerSetTaxIncluded (GncCustomer *customer, GncTaxIncluded taxincl);
-void gncCustomerSetActive (GncCustomer *customer, gboolean active);
-void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount);
-void gncCustomerSetCredit (GncCustomer *customer, gnc_numeric credit);
-void gncCustomerSetCurrency (GncCustomer *customer, gnc_commodity *currency);
-
-void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override);
-void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table);
-
-void gncCustomerAddJob (GncCustomer *customer, GncJob *job);
-void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job);
-
-/** @} */
-
-/** @name Get Functions
- @{ */
-/** Return a pointer to the instance gncCustomer that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncCustomer * gncCustomerLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncCustomer * gncCustomerLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_CUSTOMER, GncCustomer);
-}
-
-const char * gncCustomerGetID (const GncCustomer *customer);
-const char * gncCustomerGetName (const GncCustomer *customer);
-GncAddress * gncCustomerGetAddr (const GncCustomer *customer);
-GncAddress * gncCustomerGetShipAddr (const GncCustomer *customer);
-const char * gncCustomerGetNotes (const GncCustomer *customer);
-GncBillTerm * gncCustomerGetTerms (const GncCustomer *customer);
-GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *customer);
-gboolean gncCustomerGetActive (const GncCustomer *customer);
-gnc_numeric gncCustomerGetDiscount (const GncCustomer *customer);
-gnc_numeric gncCustomerGetCredit (const GncCustomer *customer);
-gnc_commodity * gncCustomerGetCurrency (const GncCustomer *customer);
-
-gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer);
-GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer);
-
-GList * gncCustomerGetJoblist (const GncCustomer *customer, gboolean show_all);
-/** @} */
-
-gboolean gncCustomerIsDirty (GncCustomer *customer);
-int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b);
-gboolean gncCustomerEqual(const GncCustomer *a, const GncCustomer *b);
-
-#define CUSTOMER_ID			"id"
-#define CUSTOMER_NAME		"name"
-#define CUSTOMER_ADDR		"addr"
-#define CUSTOMER_SHIPADDR	"shipaddr"
-#define CUSTOMER_NOTES 		"notes"
-#define CUSTOMER_DISCOUNT 	"amount of discount"
-#define CUSTOMER_CREDIT 	"amount of credit"
-#define CUSTOMER_TT_OVER 	"tax table override"
-#define CUSTOMER_TAX_INC    "customer_tax_included"
-#define CUSTOMER_TERMS      "customer_terms"
-#define CUSTOMER_ACTIVE     "customer_is_active"
-#define CUSTOMER_SLOTS      "customer_values"
-
-/** @deprecated functions, should be removed */
-#define gncCustomerGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-#define gncCustomerRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
-#define gncCustomerGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
-#define gncCustomerLookupDirect(g,b) gncCustomerLookup((b), &(g))
-
-#endif /* GNC_CUSTOMER_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncCustomerP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomerP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncCustomerP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,58 +0,0 @@
-/********************************************************************\
- * gncCustomerP.h -- the Core Customer Interface                    *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_CUSTOMERP_H_
-#define GNC_CUSTOMERP_H_
-
-#include "gncCustomer.h"
-
-gboolean gncCustomerRegister (void);
-gint64 gncCustomerNextID (QofBook *book);
-
-/** The gncCloneCustomer() routine makes a copy of the indicated
- *  customer, placing it in the indicated book.  It copies
- *  the addresses, credits, currency, billing terms and jobs.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-GncCustomer * gncCloneCustomer (GncCustomer *from,  QofBook *book);
-
-/** The gncCustomerObtainTwin() will find the 'twin' of the
- *  indicated customer in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneCustomer()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncCustomer * gncCustomerObtainTwin (GncCustomer *from, QofBook *book);
-
-#define gncCustomerSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-#endif /* GNC_CUSTOMERP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncEmployee.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEmployee.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,724 +0,0 @@
-/********************************************************************\
- * gncEmployee.c -- the Core Employee Interface                     *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001,2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "Account.h"
-#include "gnc-commodity.h"
-#include "gncAddressP.h"
-#include "gncEmployee.h"
-#include "gncEmployeeP.h"
-
-static gint gs_address_event_handler_id = 0;
-static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                                      gpointer user_data, gpointer event_data);
-
-struct _gncEmployee
-{
-    QofInstance     inst;
-    char *          id;
-    char *          username;
-    GncAddress *    addr;
-    gnc_commodity * currency;
-    gboolean        active;
-
-    char *          language;
-    char *          acl;
-    gnc_numeric     workday;
-    gnc_numeric     rate;
-
-    Account *        ccard_acc;
-};
-
-struct _gncEmployeeClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME        GNC_ID_EMPLOYEE
-
-G_INLINE_FUNC void mark_employee (GncEmployee *employee);
-void mark_employee (GncEmployee *employee)
-{
-    qof_instance_set_dirty(&employee->inst);
-    qof_event_gen (&employee->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* ============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_USERNAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncEmployee, gnc_employee, QOF_TYPE_INSTANCE);
-
-static void
-gnc_employee_init(GncEmployee* emp)
-{
-}
-
-static void
-gnc_employee_dispose(GObject *empp)
-{
-    G_OBJECT_CLASS(gnc_employee_parent_class)->dispose(empp);
-}
-
-static void
-gnc_employee_finalize(GObject* empp)
-{
-    G_OBJECT_CLASS(gnc_employee_parent_class)->finalize(empp);
-}
-
-static void
-gnc_employee_get_property (GObject         *object,
-                           guint            prop_id,
-                           GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncEmployee *emp;
-
-    g_return_if_fail(GNC_IS_EMPLOYEE(object));
-
-    emp = GNC_EMPLOYEE(object);
-    switch (prop_id)
-    {
-    case PROP_USERNAME:
-        g_value_set_string(value, emp->username);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_employee_set_property (GObject         *object,
-                           guint            prop_id,
-                           const GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncEmployee *emp;
-
-    g_return_if_fail(GNC_IS_EMPLOYEE(object));
-
-    emp = GNC_EMPLOYEE(object);
-    switch (prop_id)
-    {
-    case PROP_USERNAME:
-        gncEmployeeSetUsername(emp, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Get displayable name */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncEmployee* emp;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
-
-    emp = GNC_EMPLOYEE(inst);
-    return g_strdup_printf("Employee %s", emp->username);
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncEmployee* emp;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
-
-    emp = GNC_EMPLOYEE(inst);
-
-    if (GNC_IS_COMMODITY(ref))
-    {
-        return (emp->currency == GNC_COMMODITY(ref));
-    }
-    else if (GNC_IS_ACCOUNT(ref))
-    {
-        return (emp->ccard_acc == GNC_ACCOUNT(ref));
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_employee_class_init (GncEmployeeClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_employee_dispose;
-    gobject_class->finalize = gnc_employee_finalize;
-    gobject_class->set_property = gnc_employee_set_property;
-    gobject_class->get_property = gnc_employee_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_USERNAME,
-     g_param_spec_string ("username",
-                          "Employee Name",
-                          "The employee name is an arbitrary string "
-                          "assigned by the user which provides the employee "
-                          "name.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncEmployee *gncEmployeeCreate (QofBook *book)
-{
-    GncEmployee *employee;
-
-    if (!book) return NULL;
-
-    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
-    qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);
-
-    employee->id = CACHE_INSERT ("");
-    employee->username = CACHE_INSERT ("");
-    employee->language = CACHE_INSERT ("");
-    employee->acl = CACHE_INSERT ("");
-    employee->addr = gncAddressCreate (book, &employee->inst);
-    employee->workday = gnc_numeric_zero();
-    employee->rate = gnc_numeric_zero();
-    employee->active = TRUE;
-
-    if (gs_address_event_handler_id == 0)
-    {
-        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
-    }
-
-    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
-
-    return employee;
-}
-
-void gncEmployeeDestroy (GncEmployee *employee)
-{
-    if (!employee) return;
-    qof_instance_set_destroying(employee, TRUE);
-    gncEmployeeCommitEdit(employee);
-}
-
-static void gncEmployeeFree (GncEmployee *employee)
-{
-    if (!employee) return;
-
-    qof_event_gen (&employee->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (employee->id);
-    CACHE_REMOVE (employee->username);
-    CACHE_REMOVE (employee->language);
-    CACHE_REMOVE (employee->acl);
-    gncAddressBeginEdit (employee->addr);
-    gncAddressDestroy (employee->addr);
-
-    /* qof_instance_release (&employee->inst); */
-    g_object_unref (employee);
-}
-
-GncEmployee *
-gncCloneEmployee (GncEmployee *from, QofBook *book)
-{
-    GncEmployee *employee;
-    if (!book || !from) return NULL;
-
-    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
-    qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&employee->inst, &from->inst);
-
-    employee->id = CACHE_INSERT (from->id);
-    employee->username = CACHE_INSERT (from->username);
-    employee->language = CACHE_INSERT (from->language);
-    employee->acl = CACHE_INSERT (from->acl);
-    employee->addr = gncCloneAddress (from->addr, &employee->inst, book);
-    employee->workday = from->workday;
-    employee->rate = from->rate;
-    employee->active = from->active;
-    employee->currency = gnc_commodity_obtain_twin(from->currency, book);
-    employee->ccard_acc =
-        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));
-
-    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
-
-    return employee;
-}
-
-GncEmployee *
-gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
-{
-    GncEmployee *employee;
-    if (!book) return NULL;
-
-    employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!employee)
-    {
-        employee = gncCloneEmployee (from, book);
-    }
-
-    return employee;
-}
-
-/* ============================================================== */
-/* Set Functions */
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncEmployeeBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-void gncEmployeeSetID (GncEmployee *employee, const char *id)
-{
-    if (!employee) return;
-    if (!id) return;
-    SET_STR(employee, employee->id, id);
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetUsername (GncEmployee *employee, const char *username)
-{
-    if (!employee) return;
-    if (!username) return;
-    SET_STR(employee, employee->username, username);
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetLanguage (GncEmployee *employee, const char *language)
-{
-    if (!employee) return;
-    if (!language) return;
-    SET_STR(employee, employee->language, language);
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetAcl (GncEmployee *employee, const char *acl)
-{
-    if (!employee) return;
-    if (!acl) return;
-    SET_STR(employee, employee->acl, acl);
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday)
-{
-    if (!employee) return;
-    if (gnc_numeric_equal (workday, employee->workday)) return;
-    gncEmployeeBeginEdit (employee);
-    employee->workday = workday;
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate)
-{
-    if (!employee) return;
-    if (gnc_numeric_equal (rate, employee->rate)) return;
-    gncEmployeeBeginEdit (employee);
-    employee->rate = rate;
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency)
-{
-    if (!employee || !currency) return;
-    if (employee->currency &&
-            gnc_commodity_equal (employee->currency, currency))
-        return;
-    gncEmployeeBeginEdit (employee);
-    employee->currency = currency;
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetActive (GncEmployee *employee, gboolean active)
-{
-    if (!employee) return;
-    if (active == employee->active) return;
-    gncEmployeeBeginEdit (employee);
-    employee->active = active;
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc)
-{
-    if (!employee) return;
-    if (ccard_acc == employee->ccard_acc) return;
-    gncEmployeeBeginEdit (employee);
-    employee->ccard_acc = ccard_acc;
-    mark_employee (employee);
-    gncEmployeeCommitEdit (employee);
-}
-
-void
-qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent)
-{
-    GncAddress *addr;
-
-    if (!employee || !addr_ent)
-    {
-        return;
-    }
-    addr = (GncAddress*)addr_ent;
-    if (addr == employee->addr)
-    {
-        return;
-    }
-    if (employee->addr != NULL)
-    {
-        gncAddressBeginEdit(employee->addr);
-        gncAddressDestroy(employee->addr);
-    }
-    gncEmployeeBeginEdit(employee);
-    employee->addr = addr;
-    gncEmployeeCommitEdit(employee);
-}
-
-/* ============================================================== */
-/* Get Functions */
-const char * gncEmployeeGetID (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->id;
-}
-
-const char * gncEmployeeGetUsername (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->username;
-}
-
-GncAddress * gncEmployeeGetAddr (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->addr;
-}
-
-const char * gncEmployeeGetLanguage (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->language;
-}
-
-const char * gncEmployeeGetAcl (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->acl;
-}
-
-gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee)
-{
-    if (!employee) return gnc_numeric_zero();
-    return employee->workday;
-}
-
-gnc_numeric gncEmployeeGetRate (const GncEmployee *employee)
-{
-    if (!employee) return gnc_numeric_zero();
-    return employee->rate;
-}
-
-gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->currency;
-}
-
-gboolean gncEmployeeGetActive (const GncEmployee *employee)
-{
-    if (!employee) return FALSE;
-    return employee->active;
-}
-
-Account * gncEmployeeGetCCard (const GncEmployee *employee)
-{
-    if (!employee) return NULL;
-    return employee->ccard_acc;
-}
-
-gboolean gncEmployeeIsDirty (const GncEmployee *employee)
-{
-    if (!employee) return FALSE;
-    return (qof_instance_get_dirty_flag(employee)
-            || gncAddressIsDirty (employee->addr));
-}
-
-void gncEmployeeBeginEdit (GncEmployee *employee)
-{
-    qof_begin_edit(&employee->inst);
-}
-
-static void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode)
-{
-    PERR("Employee QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncEmployeeOnDone (QofInstance *inst)
-{
-    GncEmployee *employee = (GncEmployee *) inst;
-    gncAddressClearDirty (employee->addr);
-}
-
-static void emp_free (QofInstance *inst)
-{
-    GncEmployee *employee = (GncEmployee *) inst;
-    gncEmployeeFree (employee);
-}
-
-
-void gncEmployeeCommitEdit (GncEmployee *employee)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(employee))) return;
-    qof_commit_edit_part2 (&employee->inst, gncEmployeeOnError,
-                           gncEmployeeOnDone, emp_free);
-}
-
-/* ============================================================== */
-/* Other functions */
-
-int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    return(strcmp(a->username, b->username));
-}
-
-gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL ) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE);
-    g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->username, b->username) != 0)
-    {
-        PWARN("Usernames differ: %s vs %s", a->username, b->username);
-        return FALSE;
-    }
-
-    if (!gncAddressEqual(a->addr, b->addr))
-    {
-        PWARN("Addresses differ");
-        return FALSE;
-    }
-
-    if (!gnc_commodity_equal(a->currency, b->currency))
-    {
-        PWARN("Currencies differ");
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->language, b->language) != 0)
-    {
-        PWARN("Languages differ: %s vs %s", a->language, b->language);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->acl, b->acl) != 0)
-    {
-        PWARN("ACLs differ: %s vs %s", a->acl, b->acl);
-        return FALSE;
-    }
-
-    if (!xaccAccountEqual(a->ccard_acc, b->ccard_acc, TRUE))
-    {
-        PWARN("Accounts differ");
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->workday, b->workday))
-    {
-        PWARN("Workdays differ");
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->rate, b->rate))
-    {
-        PWARN("Rates differ");
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-/* Package-Private functions */
-
-static const char * _gncEmployeePrintable (gpointer item)
-{
-    GncEmployee *v = item;
-    if (!item) return NULL;
-    return gncAddressGetName(v->addr);
-}
-
-/**
- * Listens for MODIFY events from addresses.   If the address belongs to an employee,
- * mark the employee as dirty.
- *
- * @param entity Entity for the event
- * @param event_type Event type
- * @param user_data User data registered with the handler
- * @param event_data Event data passed with the event.
- */
-static void
-listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                          gpointer user_data, gpointer event_data)
-{
-    GncEmployee* empl;
-
-    if ((event_type & QOF_EVENT_MODIFY) == 0)
-    {
-        return;
-    }
-    if (!GNC_IS_ADDRESS(entity))
-    {
-        return;
-    }
-    if (!GNC_IS_EMPLOYEE(event_data))
-    {
-        return;
-    }
-    empl = GNC_EMPLOYEE(event_data);
-    gncEmployeeBeginEdit(empl);
-    mark_employee(empl);
-    gncEmployeeCommitEdit(empl);
-}
-
-static QofObject gncEmployeeDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Employee",
-    DI(.create            = ) (gpointer)gncEmployeeCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) _gncEmployeePrintable,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncEmployeeRegister (void)
-{
-    static QofParam params[] =
-    {
-        { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, (QofSetterFunc)gncEmployeeSetID },
-        {
-            EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername,
-            (QofSetterFunc)gncEmployeeSetUsername
-        },
-        {
-            EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage,
-            (QofSetterFunc)gncEmployeeSetLanguage
-        },
-        { EMPLOYEE_ACL, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetAcl, (QofSetterFunc)gncEmployeeSetAcl },
-        {
-            EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetWorkday,
-            (QofSetterFunc)gncEmployeeSetWorkday
-        },
-        { EMPLOYEE_RATE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetRate, (QofSetterFunc)gncEmployeeSetRate },
-        { EMPLOYEE_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncEmployeeGetAddr, (QofSetterFunc)qofEmployeeSetAddr },
-        { EMPLOYEE_CC,  GNC_ID_ACCOUNT, (QofAccessFunc)gncEmployeeGetCCard, (QofSetterFunc)gncEmployeeSetCCard },
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params);
-
-    return qof_object_register (&gncEmployeeDesc);
-}
-
-gint64 gncEmployeeNextID (QofBook *book)
-{
-    return qof_book_get_counter (book, _GNC_MOD_NAME);
-}

Deleted: gnucash/trunk/src/business/business-core/gncEmployee.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEmployee.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,127 +0,0 @@
-/********************************************************************\
- * gncEmployee.h -- the Core Employee Interface                     *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Employee
-    @{ */
-/** @file gncEmployee.h
-    @brief Employee Interface
-    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_EMPLOYEE_H_
-#define GNC_EMPLOYEE_H_
-
-typedef struct _gncEmployee GncEmployee;
-typedef struct _gncEmployeeClass GncEmployeeClass;
-
-#include "gncAddress.h"
-#include "Account.h"
-
-#define GNC_ID_EMPLOYEE "gncEmployee"
-
-/* --- type macros --- */
-#define GNC_TYPE_EMPLOYEE            (gnc_employee_get_type ())
-#define GNC_EMPLOYEE(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_EMPLOYEE, GncEmployee))
-#define GNC_EMPLOYEE_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_EMPLOYEE, GncEmployeeClass))
-#define GNC_IS_EMPLOYEE(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_EMPLOYEE))
-#define GNC_IS_EMPLOYEE_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_EMPLOYEE))
-#define GNC_EMPLOYEE_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_EMPLOYEE, GncEmployeeClass))
-GType gnc_employee_get_type(void);
-
-/** @name Create/Destroy Functions
- @{ */
-GncEmployee *gncEmployeeCreate (QofBook *book);
-void gncEmployeeDestroy (GncEmployee *employee);
-void gncEmployeeBeginEdit (GncEmployee *employee);
-void gncEmployeeCommitEdit (GncEmployee *employee);
-int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b);
-/** @} */
-
-/** @name Set Functions
- @{ */
-void gncEmployeeSetID (GncEmployee *employee, const char *id);
-void gncEmployeeSetUsername (GncEmployee *employee, const char *username);
-void gncEmployeeSetLanguage (GncEmployee *employee, const char *language);
-void gncEmployeeSetAcl (GncEmployee *employee, const char *acl);
-void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday);
-void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate);
-void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity * currency);
-void gncEmployeeSetActive (GncEmployee *employee, gboolean active);
-void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc);
-void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent);
-
-/** @} */
-
-/** @name Get Functions
- @{ */
-QofBook * gncEmployeeGetBook (GncEmployee *employee);
-const char * gncEmployeeGetID (const GncEmployee *employee);
-const char * gncEmployeeGetUsername (const GncEmployee *employee);
-GncAddress * gncEmployeeGetAddr (const GncEmployee *employee);
-const char * gncEmployeeGetLanguage (const GncEmployee *employee);
-const char * gncEmployeeGetAcl (const GncEmployee *employee);
-gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee);
-gnc_numeric gncEmployeeGetRate (const GncEmployee *employee);
-gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee);
-gboolean gncEmployeeGetActive (const GncEmployee *employee);
-Account * gncEmployeeGetCCard (const GncEmployee *employee);
-/** @} */
-
-
-/** Return a pointer to the instance gncEmployee that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncEmployee * gncEmployeeLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncEmployee * gncEmployeeLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_EMPLOYEE, GncEmployee);
-}
-
-gboolean gncEmployeeIsDirty (const GncEmployee *employee);
-gboolean gncEmployeeEqual(const GncEmployee* e1, const GncEmployee* e2);
-
-#define EMPLOYEE_ID			"id"
-#define EMPLOYEE_USERNAME	"username"
-#define EMPLOYEE_ADDR		"addr"
-#define EMPLOYEE_LANGUAGE 	"native language"
-#define EMPLOYEE_ACL		"acl"
-#define EMPLOYEE_WORKDAY	"workday"
-#define EMPLOYEE_RATE		"rate"
-#define EMPLOYEE_CC    "credit_card_account"
-
-/** deprecated routines */
-#define gncEmployeeGetGUID(E) qof_entity_get_guid(QOF_INSTANCE(E))
-#define gncEmployeeGetBook(E) qof_instance_get_book(QOF_INSTANCE(E))
-#define gncEmployeeRetGUID(E) (E ? *(qof_entity_get_guid(QOF_INSTANCE(E))) : *(guid_null()))
-#define gncEmployeeLookupDirect(G,B) gncEmployeeLookup((B),&(G))
-
-#endif /* GNC_EMPLOYEE_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncEmployeeP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployeeP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEmployeeP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,62 +0,0 @@
-/********************************************************************\
- * gncEmployeeP.h -- the Core Employee Interface
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_EMPLOYEEP_H_
-#define GNC_EMPLOYEEP_H_
-
-#include "gncEmployee.h"
-
-gboolean gncEmployeeRegister (void);
-gint64 gncEmployeeNextID (QofBook *book);
-
-/** The gncCloneEmployee() routine makes a copy of the indicated
- *  employee, placing it in the indicated book.  It copies
- *  the username, address, currency, ccard account, etc.
- *  It also copies (as needed) both parents and children, so that
- *  the parent-child relationship is correctly mirrored in the
- *  clone.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *);
-
-/** The gncEmployeeObtainTwin() will find the 'twin' of the
- *  indicated employee in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneEmployee()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book);
-
-#define gncEmployeeSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-#endif /* GNC_EMPLOYEEP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEntry.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,1602 +0,0 @@
-/********************************************************************\
- * gncEntry.c -- the Core Business Entry Interface                  *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001,2002 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-
-#include "gnc-commodity.h"
-
-#include "gncEntry.h"
-#include "gncEntryP.h"
-#include "gncInvoice.h"
-#include "gncOrder.h"
-
-struct _gncEntry
-{
-    QofInstance inst;
-
-    Timespec	date;
-    Timespec	date_entered;
-    char *	desc;
-    char *	action;
-    char *	notes;
-    gnc_numeric 	quantity;
-
-    /* customer invoice data */
-    Account *	i_account;
-    gnc_numeric 	i_price;
-    gboolean	i_taxable;
-    gboolean	i_taxincluded;
-    GncTaxTable *	i_tax_table;
-    gnc_numeric 	i_discount;
-    GncAmountType	i_disc_type;
-    GncDiscountHow i_disc_how;
-
-    /* vendor bill data */
-    Account *	b_account;
-    gnc_numeric 	b_price;
-    gboolean	b_taxable;
-    gboolean	b_taxincluded;
-    GncTaxTable *	b_tax_table;
-    gboolean	billable;
-    GncOwner	billto;
-
-    /* employee bill data */
-    GncEntryPaymentType b_payment;
-
-    /* my parent(s) */
-    GncOrder *	order;
-    GncInvoice *	invoice;
-    GncInvoice *	bill;
-
-    /* CACHED VALUES */
-    gboolean	values_dirty;
-
-    /* customer invoice */
-    gnc_numeric	i_value;
-    gnc_numeric	i_value_rounded;
-    GList *	i_tax_values;
-    gnc_numeric	i_tax_value;
-    gnc_numeric	i_tax_value_rounded;
-    gnc_numeric	i_disc_value;
-    gnc_numeric	i_disc_value_rounded;
-    Timespec	i_taxtable_modtime;
-
-    /* vendor bill */
-    gnc_numeric	b_value;
-    gnc_numeric	b_value_rounded;
-    GList *	b_tax_values;
-    gnc_numeric	b_tax_value;
-    gnc_numeric	b_tax_value_rounded;
-    Timespec	b_taxtable_modtime;
-};
-
-struct _gncEntryClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-/* You must edit the functions in this block in tandem.  KEEP THEM IN
-   SYNC! */
-
-#define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);
-const char *
-gncEntryDiscountHowToString (GncDiscountHow how)
-{
-    switch (how)
-    {
-        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_PRETAX, "PRETAX");
-        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_SAMETIME, "SAMETIME");
-        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_POSTTAX, "POSTTAX");
-    default:
-        g_warning ("asked to translate unknown discount-how %d.\n", how);
-        break;
-    }
-    return(NULL);
-}
-
-const char * gncEntryPaymentTypeToString (GncEntryPaymentType type)
-{
-    switch (type)
-    {
-        GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CASH, "CASH");
-        GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CARD, "CARD");
-    default:
-        g_warning ("asked to translate unknown payment type %d.\n", type);
-        break;
-    }
-    return(NULL);
-}
-#undef GNC_RETURN_ENUM_AS_STRING
-#define GNC_RETURN_ON_MATCH(s,x,r) \
-  if(safe_strcmp((s), (str)) == 0) { *(r) = x; return(TRUE); }
-gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how)
-{
-    GNC_RETURN_ON_MATCH ("PRETAX", GNC_DISC_PRETAX, how);
-    GNC_RETURN_ON_MATCH ("SAMETIME", GNC_DISC_SAMETIME, how);
-    GNC_RETURN_ON_MATCH ("POSTTAX", GNC_DISC_POSTTAX, how);
-    g_warning ("asked to translate unknown discount-how string %s.\n",
-               str ? str : "(null)");
-
-    return(FALSE);
-}
-gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type)
-{
-    GNC_RETURN_ON_MATCH ("CASH", GNC_PAYMENT_CASH, type);
-    GNC_RETURN_ON_MATCH ("CARD", GNC_PAYMENT_CARD, type);
-    g_warning ("asked to translate unknown discount-how string %s.\n",
-               str ? str : "(null)");
-
-    return(FALSE);
-}
-#undef GNC_RETURN_ON_MATCH
-
-#define _GNC_MOD_NAME	GNC_ID_ENTRY
-
-#define SET_STR(obj, member, str) { \
-	char * tmp; \
-	\
-	if (!safe_strcmp (member, str)) return; \
-	gncEntryBeginEdit (obj); \
-	tmp = CACHE_INSERT (str); \
-	CACHE_REMOVE (member); \
-	member = tmp; \
-	}
-
-G_INLINE_FUNC void mark_entry (GncEntry *entry);
-void mark_entry (GncEntry *entry)
-{
-    qof_instance_set_dirty(&entry->inst);
-    qof_event_gen (&entry->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* ================================================================ */
-
-enum
-{
-    PROP_0,
-    PROP_DESCRIPTION
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncEntry, gnc_entry, QOF_TYPE_INSTANCE);
-
-static void
-gnc_entry_init(GncEntry* entry)
-{
-}
-
-static void
-gnc_entry_dispose(GObject *entryp)
-{
-    G_OBJECT_CLASS(gnc_entry_parent_class)->dispose(entryp);
-}
-
-static void
-gnc_entry_finalize(GObject* entryp)
-{
-    G_OBJECT_CLASS(gnc_entry_parent_class)->finalize(entryp);
-}
-
-static void
-gnc_entry_get_property (GObject         *object,
-                        guint            prop_id,
-                        GValue          *value,
-                        GParamSpec      *pspec)
-{
-    GncEntry *entry;
-
-    g_return_if_fail(GNC_IS_ENTRY(object));
-
-    entry = GNC_ENTRY(object);
-    switch (prop_id)
-    {
-    case PROP_DESCRIPTION:
-        g_value_set_string(value, entry->desc);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_entry_set_property (GObject         *object,
-                        guint            prop_id,
-                        const GValue          *value,
-                        GParamSpec      *pspec)
-{
-    GncEntry *entry;
-
-    g_return_if_fail(GNC_IS_ENTRY(object));
-
-    entry = GNC_ENTRY(object);
-    switch (prop_id)
-    {
-    case PROP_DESCRIPTION:
-        gncEntrySetDescription(entry, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Return displayable name */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncEntry* entry;
-    gchar* display_name;
-    gchar* s;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
-
-    entry = GNC_ENTRY(inst);
-    if (entry->order != NULL)
-    {
-        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->order));
-        s = g_strdup_printf("Entry in %s", display_name);
-        g_free(display_name);
-        return s;
-    }
-    if (entry->invoice != NULL)
-    {
-        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->invoice));
-        s = g_strdup_printf("Entry in %s", display_name);
-        g_free(display_name);
-        return s;
-    }
-    if (entry->bill != NULL)
-    {
-        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->bill));
-        s = g_strdup_printf("Entry in %s", display_name);
-        g_free(display_name);
-        return s;
-    }
-
-    return g_strdup_printf("Entry %p", inst);
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncEntry* entry;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
-
-    entry = GNC_ENTRY(inst);
-
-    if (GNC_IS_ACCOUNT(ref))
-    {
-        Account* acc = GNC_ACCOUNT(ref);
-        return (entry->i_account == acc || entry->b_account == acc);
-    }
-    else if (GNC_IS_TAXTABLE(ref))
-    {
-        GncTaxTable* tt = GNC_TAXTABLE(ref);
-        return (entry->i_tax_table == tt || entry->b_tax_table == tt);
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_ACCOUNT(ref) && !GNC_IS_TAXTABLE(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_entry_class_init (GncEntryClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_entry_dispose;
-    gobject_class->finalize = gnc_entry_finalize;
-    gobject_class->set_property = gnc_entry_set_property;
-    gobject_class->get_property = gnc_entry_get_property;
-
-    qof_class->get_display_name = impl_get_display_name;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_DESCRIPTION,
-     g_param_spec_string ("description",
-                          "Entry Description",
-                          "The description is an arbitrary string "
-                          "assigned by the user.  It provides identification "
-                          "for this entry.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncEntry *gncEntryCreate (QofBook *book)
-{
-    GncEntry *entry;
-    gnc_numeric zero = gnc_numeric_zero ();
-
-    if (!book) return NULL;
-
-    entry = g_object_new (GNC_TYPE_ENTRY, NULL);
-    qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book);
-
-    entry->desc = CACHE_INSERT ("");
-    entry->action = CACHE_INSERT ("");
-    entry->notes = CACHE_INSERT ("");
-    entry->quantity = zero;
-
-    entry->i_price = zero;
-    entry->i_taxable = TRUE;
-    entry->i_discount = zero;
-    entry->i_disc_type = GNC_AMT_TYPE_PERCENT;
-    entry->i_disc_how = GNC_DISC_PRETAX;
-
-    entry->b_price = zero;
-    entry->b_taxable = TRUE;
-    entry->billto.type = GNC_OWNER_CUSTOMER;
-    entry->b_payment = GNC_PAYMENT_CASH;
-
-    entry->values_dirty = TRUE;
-
-    qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL);
-
-    return entry;
-}
-
-void gncEntryDestroy (GncEntry *entry)
-{
-    if (!entry) return;
-    qof_instance_set_destroying(entry, TRUE);
-    gncEntryCommitEdit(entry);
-}
-
-static void gncEntryFree (GncEntry *entry)
-{
-    if (!entry) return;
-
-    qof_event_gen (&entry->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (entry->desc);
-    CACHE_REMOVE (entry->action);
-    CACHE_REMOVE (entry->notes);
-    if (entry->i_tax_values)
-        gncAccountValueDestroy (entry->i_tax_values);
-    if (entry->b_tax_values)
-        gncAccountValueDestroy (entry->b_tax_values);
-    if (entry->i_tax_table)
-        gncTaxTableDecRef (entry->i_tax_table);
-    if (entry->b_tax_table)
-        gncTaxTableDecRef (entry->b_tax_table);
-
-    /* qof_instance_release (&entry->inst); */
-    g_object_unref (entry);
-}
-
-GncEntry *
-gncCloneEntry (GncEntry *from, QofBook *book)
-{
-    /* XXX unfinished */
-    return NULL;
-}
-
-GncEntry *
-gncEntryObtainTwin (GncEntry *from, QofBook *book)
-{
-    GncEntry *entry;
-    if (!book) return NULL;
-
-    entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!entry)
-    {
-        entry = gncCloneEntry (from, book);
-    }
-
-    return entry;
-}
-
-
-/* ================================================================ */
-/* Set Functions */
-
-void gncEntrySetDate (GncEntry *entry, Timespec date)
-{
-    gboolean first_date = FALSE;
-    Timespec zero_time = { 0, 0 };
-
-    if (!entry) return;
-    if (timespec_equal (&entry->date, &date)) return;
-    if (timespec_equal (&entry->date, &zero_time))
-        first_date = TRUE;
-    gncEntryBeginEdit (entry);
-    entry->date = date;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-
-    /* Don't re-sort the first time we set the date on this entry */
-    if (!first_date)
-    {
-        if (entry->invoice)
-            gncInvoiceSortEntries(entry->invoice);
-        if (entry->bill)
-            gncInvoiceSortEntries(entry->bill);
-    }
-}
-
-void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
-{
-    if (!entry) return;
-    if (timespec_equal (&entry->date_entered, &date)) return;
-    gncEntryBeginEdit (entry);
-    entry->date_entered = date;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetDescription (GncEntry *entry, const char *desc)
-{
-    if (!entry || !desc) return;
-    SET_STR (entry, entry->desc, desc);
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetAction (GncEntry *entry, const char *action)
-{
-    if (!entry || !action) return;
-    SET_STR (entry, entry->action, action);
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetNotes (GncEntry *entry, const char *notes)
-{
-    if (!entry || !notes) return;
-    SET_STR (entry, entry->notes, notes);
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
-{
-    if (!entry) return;
-    if (gnc_numeric_eq (entry->quantity, quantity)) return;
-    gncEntryBeginEdit (entry);
-    entry->quantity = quantity;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-/* Customer Invoices */
-
-void gncEntrySetInvAccount (GncEntry *entry, Account *acc)
-{
-    if (!entry) return;
-    if (entry->i_account == acc) return;
-    gncEntryBeginEdit (entry);
-    entry->i_account = acc;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price)
-{
-    if (!entry) return;
-    if (gnc_numeric_eq (entry->i_price, price)) return;
-    gncEntryBeginEdit (entry);
-    entry->i_price = price;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable)
-{
-    if (!entry) return;
-    if (entry->i_taxable == taxable) return;
-    gncEntryBeginEdit (entry);
-    entry->i_taxable = taxable;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean taxincluded)
-{
-    if (!entry) return;
-    if (entry->i_taxincluded == taxincluded) return;
-    gncEntryBeginEdit (entry);
-    entry->i_taxincluded = taxincluded;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
-{
-    if (!entry) return;
-    if (entry->i_tax_table == table) return;
-    gncEntryBeginEdit (entry);
-    if (entry->i_tax_table)
-        gncTaxTableDecRef (entry->i_tax_table);
-    if (table)
-        gncTaxTableIncRef (table);
-    entry->i_tax_table = table;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount)
-{
-    if (!entry) return;
-    if (gnc_numeric_eq (entry->i_discount, discount)) return;
-    gncEntryBeginEdit (entry);
-    entry->i_discount = discount;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type)
-{
-    if (!entry) return;
-    if (entry->i_disc_type == type) return;
-
-    gncEntryBeginEdit (entry);
-    entry->i_disc_type = type;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how)
-{
-    if (!entry) return;
-    if (entry->i_disc_how == how) return;
-
-    gncEntryBeginEdit (entry);
-    entry->i_disc_how = how;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void qofEntrySetInvDiscType (GncEntry *entry, const char *type_string)
-{
-    GncAmountType type;
-
-    if (!entry) return;
-    gncAmountStringToType(type_string, &type);
-    if (entry->i_disc_type == type) return;
-    gncEntryBeginEdit (entry);
-    entry->i_disc_type = type;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-
-}
-
-void qofEntrySetInvDiscHow  (GncEntry *entry, const char *type)
-{
-    GncDiscountHow how;
-
-    if (!entry) return;
-    gncEntryBeginEdit (entry);
-    gncEntryDiscountStringToHow(type, &how);
-    if (entry->i_disc_how == how) return;
-    entry->i_disc_how = how;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-/* Vendor Bills */
-
-void gncEntrySetBillAccount (GncEntry *entry, Account *acc)
-{
-    if (!entry) return;
-    if (entry->b_account == acc) return;
-    gncEntryBeginEdit (entry);
-    entry->b_account = acc;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price)
-{
-    if (!entry) return;
-    if (gnc_numeric_eq (entry->b_price, price)) return;
-    gncEntryBeginEdit (entry);
-    entry->b_price = price;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable)
-{
-    if (!entry) return;
-    if (entry->b_taxable == taxable) return;
-    gncEntryBeginEdit (entry);
-    entry->b_taxable = taxable;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean taxincluded)
-{
-    if (!entry) return;
-    if (entry->b_taxincluded == taxincluded) return;
-    gncEntryBeginEdit (entry);
-    entry->b_taxincluded = taxincluded;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
-{
-    if (!entry) return;
-    if (entry->b_tax_table == table) return;
-    gncEntryBeginEdit (entry);
-    if (entry->b_tax_table)
-        gncTaxTableDecRef (entry->b_tax_table);
-    if (table)
-        gncTaxTableIncRef (table);
-    entry->b_tax_table = table;
-    entry->values_dirty = TRUE;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillable (GncEntry *entry, gboolean billable)
-{
-    if (!entry) return;
-    if (entry->billable == billable) return;
-
-    gncEntryBeginEdit (entry);
-    entry->billable = billable;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto)
-{
-    if (!entry || !billto) return;
-    if (gncOwnerEqual (&entry->billto, billto)) return;
-
-    gncEntryBeginEdit (entry);
-    gncOwnerCopy (billto, &entry->billto);
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type)
-{
-    if (!entry) return;
-    if (entry->b_payment == type) return;
-    gncEntryBeginEdit (entry);
-    entry->b_payment = type;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-/* Called from gncOrder when we're added to the Order */
-void gncEntrySetOrder (GncEntry *entry, GncOrder *order)
-{
-    if (!entry) return;
-    if (entry->order == order) return;
-    gncEntryBeginEdit (entry);
-    entry->order = order;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-
-    /* Generate an event modifying the Order's end-owner */
-#if 0
-    qof_event_gen (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
-                   QOF_EVENT_MODIFY, NULL);
-#endif
-}
-
-/* called from gncInvoice when we're added to the Invoice */
-void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice)
-{
-    if (!entry) return;
-    if (entry->invoice == invoice) return;
-    gncEntryBeginEdit (entry);
-    entry->invoice = invoice;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-/* called from gncInvoice when we're added to the Invoice/Bill */
-void gncEntrySetBill (GncEntry *entry, GncInvoice *bill)
-{
-    if (!entry) return;
-    if (entry->bill == bill) return;
-    gncEntryBeginEdit (entry);
-    entry->bill = bill;
-    mark_entry (entry);
-    gncEntryCommitEdit (entry);
-}
-
-void gncEntryCopy (const GncEntry *src, GncEntry *dest)
-{
-    if (!src || !dest) return;
-
-    gncEntryBeginEdit (dest);
-    dest->date 			= src->date;
-    dest->date_entered		= src->date_entered; /* ??? */
-    gncEntrySetDescription (dest, src->desc);
-    gncEntrySetAction (dest, src->action);
-    gncEntrySetNotes (dest, src->notes);
-    dest->quantity		= src->quantity;
-
-    dest->i_account		= src->i_account;
-    dest->i_price			= src->i_price;
-    dest->i_taxable		= src->i_taxable;
-    dest->i_taxincluded		= src->i_taxincluded;
-    dest->i_discount		= src->i_discount;
-    dest->i_disc_type		= src->i_disc_type;
-    dest->i_disc_how		= src->i_disc_how;
-
-    /* vendor bill data */
-    dest->b_account		= src->b_account;
-    dest->b_price			= src->b_price;
-    dest->b_taxable		= src->b_taxable;
-    dest->b_taxincluded		= src->b_taxincluded;
-    dest->billable		= src->billable;
-    dest->billto			= src->billto;
-
-    if (src->i_tax_table)
-        gncEntrySetInvTaxTable (dest, src->i_tax_table);
-
-    if (src->b_tax_table)
-        gncEntrySetBillTaxTable (dest, src->b_tax_table);
-
-    if (src->order)
-        gncOrderAddEntry (src->order, dest);
-
-    if (src->invoice)
-        gncInvoiceAddEntry (src->invoice, dest);
-
-    if (src->bill)
-        gncBillAddEntry (src->bill, dest);
-
-    dest->values_dirty = TRUE;
-    gncEntryCommitEdit (dest);
-}
-
-/* ================================================================ */
-/* Get Functions */
-
-Timespec gncEntryGetDate (const GncEntry *entry)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!entry) return ts;
-    return entry->date;
-}
-
-Timespec gncEntryGetDateEntered (const GncEntry *entry)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!entry) return ts;
-    return entry->date_entered;
-}
-
-const char * gncEntryGetDescription (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->desc;
-}
-
-const char * gncEntryGetAction (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->action;
-}
-
-const char * gncEntryGetNotes (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->notes;
-}
-
-gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
-{
-    if (!entry) return gnc_numeric_zero();
-    return entry->quantity;
-}
-
-/* Customer Invoice */
-
-Account * gncEntryGetInvAccount (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->i_account;
-}
-
-gnc_numeric gncEntryGetInvPrice (const GncEntry *entry)
-{
-    if (!entry) return gnc_numeric_zero();
-    return entry->i_price;
-}
-
-gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry)
-{
-    if (!entry) return gnc_numeric_zero();
-    return entry->i_discount;
-}
-
-GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
-{
-    if (!entry) return 0;
-    return entry->i_disc_type;
-}
-
-GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
-{
-    if (!entry) return 0;
-    return entry->i_disc_how;
-}
-
-char* qofEntryGetInvDiscType (const GncEntry *entry)
-{
-    char *type_string;
-
-    if (!entry) return 0;
-    type_string = g_strdup(gncAmountTypeToString(entry->i_disc_type));
-    return type_string;
-}
-
-char* qofEntryGetInvDiscHow (const GncEntry *entry)
-{
-    char *type_string;
-
-    if (!entry) return 0;
-    type_string = g_strdup(gncEntryDiscountHowToString(entry->i_disc_how));
-    return type_string;
-}
-
-gboolean gncEntryGetInvTaxable (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return entry->i_taxable;
-}
-
-gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return entry->i_taxincluded;
-}
-
-GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->i_tax_table;
-}
-
-/* vendor bills */
-
-Account * gncEntryGetBillAccount (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->b_account;
-}
-
-gnc_numeric gncEntryGetBillPrice (const GncEntry *entry)
-{
-    if (!entry) return gnc_numeric_zero();
-    return entry->b_price;
-}
-
-gboolean gncEntryGetBillTaxable (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return entry->b_taxable;
-}
-
-gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return entry->b_taxincluded;
-}
-
-GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->b_tax_table;
-}
-
-gboolean gncEntryGetBillable (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return entry->billable;
-}
-
-GncOwner * gncEntryGetBillTo (GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return &entry->billto;
-}
-
-GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry)
-{
-    if (!entry) return 0;
-    return entry->b_payment;
-}
-
-GncInvoice * gncEntryGetInvoice (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->invoice;
-}
-
-GncInvoice * gncEntryGetBill (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->bill;
-}
-
-GncOrder * gncEntryGetOrder (const GncEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->order;
-}
-
-/* ================================================================ */
-/*
- * This is the logic of computing the total for an Entry, so you know
- * what values to put into various Splits or to display in the ledger.
- * In other words, we combine the quantity, unit-price, discount and
- * taxes together, depending on various flags.
- *
- * There are four potental ways to combine these numbers:
- * Discount:     Pre-Tax   Post-Tax
- *   Tax   :     Included  Not-Included
- *
- * The process is relatively simple:
- *
- *  1) compute the agregate price (price*qty)
- *  2) if taxincluded, then back-compute the agregate pre-tax price
- *  3) apply discount and taxes in the appropriate order
- *  4) return the requested results.
- *
- * step 2 can be done with agregate taxes; no need to compute them all
- * unless the caller asked for the tax_value.
- *
- * Note that the returned "value" is such that value + tax == "total
- * to pay," which means in the case of tax-included that the returned
- * "value" may be less than the agregate price, even without a
- * discount.  If you want to display the tax-included value, you need
- * to add the value and taxes together.  In other words, the value is
- * the amount the merchant gets; the taxes are the amount the gov't
- * gets, and the customer pays the sum or value + taxes.
- *
- * The SCU is the denominator to convert the value.
- *
- * The discount return value is just for entertainment -- you may way
- * to let a consumer know how much they saved.
- */
-void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
-                           const GncTaxTable *tax_table, gboolean tax_included,
-                           gnc_numeric discount, GncAmountType discount_type,
-                           GncDiscountHow discount_how, int SCU,
-                           gnc_numeric *value, gnc_numeric *discount_value,
-                           GList **tax_value)
-{
-    gnc_numeric	aggregate;
-    gnc_numeric	pretax;
-    gnc_numeric	result;
-    gnc_numeric	tax;
-    gnc_numeric	percent = gnc_numeric_create (100, 1);
-    gnc_numeric	tpercent = gnc_numeric_zero ();
-    gnc_numeric	tvalue = gnc_numeric_zero ();
-
-    GList * 	entries = gncTaxTableGetEntries (tax_table);
-    GList * 	node;
-
-    /* Step 1: compute the aggregate price */
-
-    aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-
-    /* Step 2: compute the pre-tax aggregate */
-
-    /* First, compute the aggregate tpercent and tvalue numbers */
-    for (node = entries; node; node = node->next)
-    {
-        GncTaxTableEntry *entry = node->data;
-        gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
-
-        switch (gncTaxTableEntryGetType (entry))
-        {
-        case GNC_AMT_TYPE_VALUE:
-            tvalue = gnc_numeric_add (tvalue, amount, GNC_DENOM_AUTO,
-                                      GNC_DENOM_LCD);
-            break;
-        case GNC_AMT_TYPE_PERCENT:
-            tpercent = gnc_numeric_add (tpercent, amount, GNC_DENOM_AUTO,
-                                        GNC_DENOM_LCD);
-            break;
-        default:
-            g_warning ("Unknown tax type: %d", gncTaxTableEntryGetType (entry));
-        }
-    }
-    /* now we need to convert from 5% -> .05 */
-    tpercent = gnc_numeric_div (tpercent, percent, GNC_DENOM_AUTO,
-                                GNC_DENOM_LCD);
-
-    /* Next, actually compute the pre-tax aggregate value based on the
-     * taxincluded flag.
-     */
-    if (tax_table && tax_included)
-    {
-        /* Back-compute the pre-tax aggregate value.
-         * We know that aggregate = pretax + pretax*tpercent + tvalue, so
-         * pretax = (aggregate-tvalue)/(1+tpercent)
-         */
-        pretax = gnc_numeric_sub (aggregate, tvalue, GNC_DENOM_AUTO,
-                                  GNC_DENOM_LCD);
-        pretax = gnc_numeric_div (pretax,
-                                  gnc_numeric_add (tpercent,
-                                          gnc_numeric_create (1, 1),
-                                          GNC_DENOM_AUTO, GNC_DENOM_LCD),
-                                  GNC_DENOM_AUTO, GNC_DENOM_LCD);
-    }
-    else
-    {
-        pretax = aggregate;
-    }
-
-    /* Step 3:  apply discount and taxes in the appropriate order */
-
-    /*
-     * There are two ways to apply discounts and taxes.  In one way, you
-     * always compute the discount off the pretax number, and compute
-     * the taxes off of either the pretax value or "pretax-discount"
-     * value.  In the other way, you always compute the tax on "pretax",
-     * and compute the discount on either "pretax" or "pretax+taxes".
-     *
-     * I don't know which is the "correct" way.
-     */
-
-    /*
-     * Type:	discount	tax
-     * PRETAX	pretax		pretax-discount
-     * SAMETIME	pretax		pretax
-     * POSTTAX	pretax+tax	pretax
-     */
-
-    switch (discount_how)
-    {
-    case GNC_DISC_PRETAX:
-    case GNC_DISC_SAMETIME:
-        /* compute the discount from pretax */
-
-        if (discount_type == GNC_AMT_TYPE_PERCENT)
-        {
-            discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
-                                        GNC_DENOM_LCD);
-            discount = gnc_numeric_mul (pretax, discount, GNC_DENOM_AUTO,
-                                        GNC_DENOM_LCD);
-        }
-
-        result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-
-        /* Figure out when to apply the tax, pretax or pretax-discount */
-        if (discount_how == GNC_DISC_PRETAX)
-            pretax = result;
-        break;
-
-    case GNC_DISC_POSTTAX:
-        /* compute discount on pretax+taxes */
-
-        if (discount_type == GNC_AMT_TYPE_PERCENT)
-        {
-            gnc_numeric after_tax;
-
-            tax = gnc_numeric_mul (pretax, tpercent, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-            after_tax = gnc_numeric_add (pretax, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-            after_tax = gnc_numeric_add (after_tax, tvalue, GNC_DENOM_AUTO,
-                                         GNC_DENOM_LCD);
-            discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
-                                        GNC_DENOM_LCD);
-            discount = gnc_numeric_mul (after_tax, discount, GNC_DENOM_AUTO,
-                                        GNC_DENOM_LCD);
-        }
-
-        result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-        break;
-
-    default:
-        g_warning ("unknown DiscountHow value: %d", discount_how);
-    }
-
-    /* Step 4:  return the requested results. */
-
-    /* result == amount merchant gets
-     * discount == amount of discount
-     * need to compute taxes (based on 'pretax') if the caller wants it.
-     */
-
-    if (discount_value != NULL)
-    {
-        if (SCU) discount = gnc_numeric_convert(discount, SCU, GNC_RND_ROUND);
-        *discount_value = discount;
-    }
-
-    if (value != NULL)
-    {
-        if (SCU) result = gnc_numeric_convert(result, SCU, GNC_RND_ROUND);
-        *value = result;
-    }
-
-    /* Now... Compute the list of tax values (if the caller wants it) */
-
-    if (tax_value != NULL)
-    {
-        GList *	taxes = NULL;
-
-        for (node = entries; node; node = node->next)
-        {
-            GncTaxTableEntry *entry = node->data;
-            Account *acc = gncTaxTableEntryGetAccount (entry);
-            gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
-
-            g_return_if_fail (acc);
-
-            switch (gncTaxTableEntryGetType (entry))
-            {
-            case GNC_AMT_TYPE_VALUE:
-                if (SCU) amount = gnc_numeric_convert(amount, SCU, GNC_RND_ROUND);
-                taxes = gncAccountValueAdd (taxes, acc, amount);
-                break;
-            case GNC_AMT_TYPE_PERCENT:
-                amount = gnc_numeric_div (amount, percent, GNC_DENOM_AUTO,
-                                          GNC_DENOM_LCD);
-                tax = gnc_numeric_mul (pretax, amount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-                if (SCU) tax = gnc_numeric_convert(tax, SCU, GNC_RND_ROUND);
-                taxes = gncAccountValueAdd (taxes, acc, tax);
-                break;
-            default:
-                break;
-            }
-        }
-        *tax_value = taxes;
-    }
-
-    return;
-}
-
-static int
-get_entry_commodity_denom (const GncEntry *entry)
-{
-    gnc_commodity *c;
-    if (!entry)
-        return 0;
-    if (entry->invoice)
-    {
-        c = gncInvoiceGetCurrency (entry->invoice);
-        if (c)
-            return (gnc_commodity_get_fraction (c));
-    }
-    if (entry->bill)
-    {
-        c = gncInvoiceGetCurrency (entry->bill);
-        if (c)
-            return (gnc_commodity_get_fraction (c));
-    }
-    return 100000;
-}
-
-static void
-gncEntryRecomputeValues (GncEntry *entry)
-{
-    int denom;
-
-    /* See if either tax table changed since we last computed values */
-    if (entry->i_tax_table)
-    {
-        Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
-        if (timespec_cmp (&entry->i_taxtable_modtime, &modtime))
-        {
-            entry->values_dirty = TRUE;
-            entry->i_taxtable_modtime = modtime;
-        }
-    }
-    if (entry->b_tax_table)
-    {
-        Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
-        if (timespec_cmp (&entry->b_taxtable_modtime, &modtime))
-        {
-            entry->values_dirty = TRUE;
-            entry->b_taxtable_modtime = modtime;
-        }
-    }
-
-    if (!entry->values_dirty)
-        return;
-
-    /* Clear the last-computed tax values */
-    if (entry->i_tax_values)
-    {
-        gncAccountValueDestroy (entry->i_tax_values);
-        entry->i_tax_values = NULL;
-    }
-    if (entry->b_tax_values)
-    {
-        gncAccountValueDestroy (entry->b_tax_values);
-        entry->b_tax_values = NULL;
-    }
-
-    /* Determine the commodity denominator */
-    denom = get_entry_commodity_denom (entry);
-
-    /* Compute the invoice values */
-    gncEntryComputeValue (entry->quantity, entry->i_price,
-                          (entry->i_taxable ? entry->i_tax_table : NULL),
-                          entry->i_taxincluded,
-                          entry->i_discount, entry->i_disc_type,
-                          entry->i_disc_how,
-                          denom,
-                          &(entry->i_value), &(entry->i_disc_value),
-                          &(entry->i_tax_values));
-
-    /* Compute the bill values */
-    gncEntryComputeValue (entry->quantity, entry->b_price,
-                          (entry->b_taxable ? entry->b_tax_table : NULL),
-                          entry->b_taxincluded,
-                          gnc_numeric_zero(), GNC_AMT_TYPE_VALUE, GNC_DISC_PRETAX,
-                          denom,
-                          &(entry->b_value), NULL, &(entry->b_tax_values));
-
-    entry->i_value_rounded = gnc_numeric_convert (entry->i_value, denom,
-                             GNC_RND_ROUND);
-    entry->i_disc_value_rounded = gnc_numeric_convert (entry->i_disc_value, denom,
-                                  GNC_RND_ROUND);
-    entry->i_tax_value = gncAccountValueTotal (entry->i_tax_values);
-    entry->i_tax_value_rounded = gnc_numeric_convert (entry->i_tax_value, denom,
-                                 GNC_RND_ROUND);
-
-    entry->b_value_rounded = gnc_numeric_convert (entry->b_value, denom,
-                             GNC_RND_ROUND);
-    entry->b_tax_value = gncAccountValueTotal (entry->b_tax_values);
-    entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom,
-                                 GNC_RND_ROUND);
-    entry->values_dirty = FALSE;
-}
-
-void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
-                       gnc_numeric *discount_value, gnc_numeric *tax_value,
-                       GList **tax_values)
-{
-    if (!entry) return;
-    gncEntryRecomputeValues (entry);
-    if (value)
-        *value = (is_inv ? entry->i_value : entry->b_value);
-    if (discount_value)
-        *discount_value = (is_inv ? entry->i_disc_value : gnc_numeric_zero());
-    if (tax_value)
-        *tax_value = (is_inv ? entry->i_tax_value : entry->b_tax_value);
-    if (tax_values)
-        *tax_values = (is_inv ? entry->i_tax_values : entry->b_tax_values);
-}
-
-gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv)
-{
-    if (!entry) return gnc_numeric_zero();
-    gncEntryRecomputeValues (entry);
-    return (is_inv ? entry->i_value_rounded : entry->b_value_rounded);
-}
-
-gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv)
-{
-    if (!entry) return gnc_numeric_zero();
-    gncEntryRecomputeValues (entry);
-    return (is_inv ? entry->i_tax_value_rounded : entry->b_tax_value_rounded);
-}
-
-AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv)
-{
-    if (!entry) return NULL;
-    gncEntryRecomputeValues (entry);
-    return (is_inv ? entry->i_tax_values : entry->b_tax_values);
-}
-
-gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
-{
-    if (!entry) return gnc_numeric_zero();
-    gncEntryRecomputeValues (entry);
-    return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero());
-}
-
-/* XXXX this exsitnace of this routine is just wrong */
-gboolean gncEntryIsOpen (const GncEntry *entry)
-{
-    if (!entry) return FALSE;
-    return (qof_instance_get_editlevel(entry) > 0);
-}
-
-/* ================================================================ */
-
-void gncEntryBeginEdit (GncEntry *entry)
-{
-    qof_begin_edit(&entry->inst);
-}
-
-static void gncEntryOnError (QofInstance *entry, QofBackendError errcode)
-{
-    PERR("Entry QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncEntryOnDone (QofInstance *inst) {}
-
-static void entry_free (QofInstance *inst)
-{
-    GncEntry *entry = (GncEntry *)inst;
-    gncEntryFree (entry);
-}
-
-void gncEntryCommitEdit (GncEntry *entry)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(entry))) return;
-    qof_commit_edit_part2 (&entry->inst, gncEntryOnError,
-                           gncEntryOnDone, entry_free);
-}
-
-int gncEntryCompare (const GncEntry *a, const GncEntry *b)
-{
-    int compare;
-
-    if (a == b) return 0;
-    if (!a && b) return -1;
-    if (a && !b) return 1;
-
-    compare = timespec_cmp (&(a->date), &(b->date));
-    if (compare) return compare;
-
-    compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
-    if (compare) return compare;
-
-    compare = safe_strcmp (a->desc, b->desc);
-    if (compare) return compare;
-
-    compare = safe_strcmp (a->action, b->action);
-    if (compare) return compare;
-
-    return qof_instance_guid_compare(a, b);
-}
-
-#define CHECK_STRING(X, Y, FIELD) \
-    if (safe_strcmp((X)->FIELD, (Y)->FIELD) != 0) \
-    { \
-        PWARN("%s differ: %s vs %s", #FIELD, (X)->FIELD, (Y)->FIELD); \
-        return FALSE; \
-    }
-
-#define CHECK_ACCOUNT(X, Y, FIELD) \
-    if (!xaccAccountEqual((X)->FIELD, (Y)->FIELD, TRUE)) \
-    { \
-        PWARN("%s differ", #FIELD); \
-        return FALSE; \
-    }
-
-#define CHECK_NUMERIC(X, Y, FIELD) \
-    if (!gnc_numeric_equal((X)->FIELD, (Y)->FIELD)) \
-    { \
-        PWARN("%s differ", #FIELD); \
-        return FALSE; \
-    }
-
-#define CHECK_VALUE(X, Y, FIELD) \
-    if ((X)->FIELD != (Y)->FIELD) \
-    { \
-        PWARN("%s differ", #FIELD); \
-        return FALSE; \
-    }
-
-gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_ENTRY(a), FALSE);
-    g_return_val_if_fail(GNC_IS_ENTRY(b), FALSE);
-
-    CHECK_STRING(a, b, desc);
-    CHECK_STRING(a, b, action);
-    CHECK_STRING(a, b, notes);
-    CHECK_NUMERIC(a, b, quantity);
-
-    if (a->invoice != NULL)
-    {
-        CHECK_ACCOUNT(a, b, i_account);
-        CHECK_NUMERIC(a, b, i_price);
-        CHECK_VALUE(a, b, i_taxable);
-        CHECK_VALUE(a, b, i_taxincluded);
-        if (!gncTaxTableEqual(a->i_tax_table, b->i_tax_table))
-        {
-            PWARN("i_tax_table differ");
-            return FALSE;
-        }
-
-        CHECK_NUMERIC(a, b, i_discount);
-        CHECK_VALUE(a, b, i_disc_type);
-        CHECK_VALUE(a, b, i_disc_how);
-        CHECK_NUMERIC(a, b, i_value);
-        CHECK_NUMERIC(a, b, i_value_rounded);
-        CHECK_NUMERIC(a, b, i_tax_value);
-        CHECK_NUMERIC(a, b, i_tax_value_rounded);
-        CHECK_NUMERIC(a, b, i_disc_value);
-        CHECK_NUMERIC(a, b, i_disc_value_rounded);
-
-#if 0
-        Timespec	date;
-        Timespec	date_entered;
-
-        /* employee bill data */
-        GncEntryPaymentType b_payment;
-
-        /* customer invoice */
-        GList *	i_tax_values;
-        Timespec	i_taxtable_modtime;
-
-#endif
-    }
-
-    if (a->bill != NULL)
-    {
-        CHECK_ACCOUNT(a, b, b_account);
-        CHECK_NUMERIC(a, b, b_price);
-
-        CHECK_NUMERIC(a, b, b_value);
-        CHECK_NUMERIC(a, b, b_value_rounded);
-        CHECK_NUMERIC(a, b, b_tax_value);
-        CHECK_NUMERIC(a, b, b_tax_value_rounded);
-#if 0
-        Timespec	date;
-        Timespec	date_entered;
-
-        /* vendor bill data */
-        gboolean	b_taxable;
-        gboolean	b_taxincluded;
-        GncTaxTable *	b_tax_table;
-        gboolean	billable;
-        GncOwner	billto;
-
-        /* employee bill data */
-        GncEntryPaymentType b_payment;
-
-        /* vendor bill */
-        GList *	b_tax_values;
-        Timespec	b_taxtable_modtime;
-#endif
-    }
-    /* FIXME: Need real tests */
-
-    return TRUE;
-}
-
-/* ============================================================= */
-/* Object declaration */
-
-static QofObject gncEntryDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Order/Invoice/Bill Entry",
-    DI(.create            = ) (gpointer)gncEntryCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) NULL,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncEntryRegister (void)
-{
-    static QofParam params[] =
-    {
-        { ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, (QofSetterFunc)gncEntrySetDate },
-        { ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, (QofSetterFunc)gncEntrySetDateEntered },
-        { ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, (QofSetterFunc)gncEntrySetDescription },
-        { ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, (QofSetterFunc)gncEntrySetAction },
-        { ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, (QofSetterFunc)gncEntrySetNotes },
-        { ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, (QofSetterFunc)gncEntrySetQuantity },
-        { ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, (QofSetterFunc)gncEntrySetInvPrice },
-        { ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, (QofSetterFunc)gncEntrySetBillPrice },
-        { ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL },
-        { ENTRY_IACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetInvAccount,  (QofSetterFunc)gncEntrySetInvAccount  },
-        { ENTRY_BACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetBillAccount, (QofSetterFunc)gncEntrySetBillAccount },
-        { ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL },
-        {
-            ENTRY_INV_DISC_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscType,
-            (QofSetterFunc)qofEntrySetInvDiscType
-        },
-        {
-            ENTRY_INV_DISC_HOW, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscHow,
-            (QofSetterFunc)qofEntrySetInvDiscHow
-        },
-        {
-            ENTRY_INV_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
-            (QofSetterFunc)gncEntrySetInvTaxable
-        },
-        {
-            ENTRY_INV_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxIncluded,
-            (QofSetterFunc)gncEntrySetInvTaxIncluded
-        },
-        {
-            ENTRY_BILL_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
-            (QofSetterFunc)gncEntrySetInvTaxable
-        },
-        {
-            ENTRY_BILL_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillTaxIncluded,
-            (QofSetterFunc)gncEntrySetBillTaxIncluded
-        },
-        { ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, (QofSetterFunc)gncEntrySetBillable },
-        { ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, (QofSetterFunc)gncEntrySetBillTo },
-        { ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
-
-    return qof_object_register (&gncEntryDesc);
-}

Deleted: gnucash/trunk/src/business/business-core/gncEntry.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEntry.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,270 +0,0 @@
-/********************************************************************\
- * gncEntry.h -- the Core Business Entry Interface                  *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Entry
-    @{ */
-/** @file gncEntry.h
-    @brief  Business Entry Interface
-    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_ENTRY_H_
-#define GNC_ENTRY_H_
-
-typedef struct _gncEntry GncEntry;
-typedef struct _gncEntryClass GncEntryClass;
-
-typedef enum
-{
-    GNC_PAYMENT_CASH = 1,
-    GNC_PAYMENT_CARD
-} GncEntryPaymentType;
-
-typedef enum
-{
-    GNC_DISC_PRETAX = 1,
-    GNC_DISC_SAMETIME,
-    GNC_DISC_POSTTAX
-} GncDiscountHow;
-
-#ifdef GNUCASH_MAJOR_VERSION
-#include "gncBusiness.h"
-#endif
-#include "gncInvoice.h"
-#include "gncOrder.h"
-#include "gncTaxTable.h"
-#include "gncOwner.h"
-
-#define GNC_ID_ENTRY "gncEntry"
-
-/* --- type macros --- */
-#define GNC_TYPE_ENTRY            (gnc_entry_get_type ())
-#define GNC_ENTRY(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ENTRY, GncEntry))
-#define GNC_ENTRY_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ENTRY, GncEntryClass))
-#define GNC_IS_ENTRY(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ENTRY))
-#define GNC_IS_ENTRY_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ENTRY))
-#define GNC_ENTRY_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ENTRY, GncEntryClass))
-GType gnc_entry_get_type(void);
-
-/** How to apply the discount and taxes.  There are three distinct ways to
- * apply them:
- *
- * Type:	discount	tax
- * PRETAX	pretax		pretax-discount
- * SAMETIME	pretax		pretax
- * POSTTAX	pretax+tax	pretax
- */
-
-const char * gncEntryDiscountHowToString (GncDiscountHow how);
-gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how);
-
-const char * gncEntryPaymentTypeToString (GncEntryPaymentType type);
-gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type);
-
-/** @name Create/Destroy Functions
- @{ */
-GncEntry *gncEntryCreate (QofBook *book);
-void gncEntryDestroy (GncEntry *entry);
-/** @} */
-
-/* SET FUNCTIONS */
-
-/** @name Generic (shared) data
- @{ */
-void gncEntrySetDate (GncEntry *entry, Timespec date);
-void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
-void gncEntrySetDescription (GncEntry *entry, const char *desc);
-void gncEntrySetAction (GncEntry *entry, const char *action);
-void gncEntrySetNotes (GncEntry *entry, const char *notes);
-void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
-/** @} */
-
-/** @name Customer Invoices
- @{ */
-void gncEntrySetInvAccount (GncEntry *entry, Account *acc);
-void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price);
-void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable);
-void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean tax_included);
-void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table);
-void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount);
-void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type);
-void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how);
-void qofEntrySetInvDiscType (GncEntry *entry, const char *type);
-void qofEntrySetInvDiscHow  (GncEntry *entry, const char *type);
-/** @} */
-
-/** @name Vendor Bills (and Employee Expenses)
- @{ */
-void gncEntrySetBillAccount (GncEntry *entry, Account *acc);
-void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price);
-void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable);
-void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean tax_included);
-void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table);
-void gncEntrySetBillable (GncEntry *entry, gboolean billable);
-void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto);
-/** @} */
-
-/** @name employee-stuff
- @{ */
-void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type);
-/** @} */
-
-/* GET FUNCTIONS */
-/** @name Generic (shared) data
- @{ */
-Timespec gncEntryGetDate (const GncEntry *entry);
-Timespec gncEntryGetDateEntered (const GncEntry *entry);
-const char * gncEntryGetDescription (const GncEntry *entry);
-const char * gncEntryGetAction (const GncEntry *entry);
-const char * gncEntryGetNotes (const GncEntry *notes);
-gnc_numeric gncEntryGetQuantity (const GncEntry *entry);
-/** @} */
-
-/** @name Customer Invoices
- @{ */
-Account * gncEntryGetInvAccount (const GncEntry *entry);
-gnc_numeric gncEntryGetInvPrice (const GncEntry *entry);
-gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry);
-GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry);
-GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry);
-char* qofEntryGetInvDiscType (const GncEntry *entry);
-char* qofEntryGetInvDiscHow (const GncEntry *entry);
-gboolean gncEntryGetInvTaxable (const GncEntry *entry);
-gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry);
-GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry);
-/** @} */
-
-/** @name Vendor Bills (and Employee Expenses)
- @{ */
-Account * gncEntryGetBillAccount (const GncEntry *entry);
-gnc_numeric gncEntryGetBillPrice (const GncEntry *entry);
-gboolean gncEntryGetBillTaxable (const GncEntry *entry);
-gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry);
-GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry);
-gboolean gncEntryGetBillable (const GncEntry *entry);
-GncOwner *gncEntryGetBillTo (GncEntry *entry);
-
-GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry);
-/** @} */
-
-void gncEntryCopy (const GncEntry *src, GncEntry *dest);
-
-/** @name Getting Values
-
- * The first three return the rounded values -- the last returns the
- * list of unrounded account-values.  The list belongs to the entry
- * and will be destroyed, so use it quickly.
- @{
-*/
-gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv);
-gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv);
-gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv);
-typedef GList AccountValueList;
-AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv);
-
-/** Compute the Entry value, tax-value, and discount_value, based on
- * the quantity, price, discount, tax-table, and types.  The value is
- * the amount the merchant gets, the taxes are what the gov't gets,
- * and the discount is how much the customer saved.  The SCU is the
- * target denominator of the value and tax -- it should be the
- * account or commodity SCU of the target.
- *
- * The tax_values list is the property of the entry and will be
- * destroyed automatically, so use it quickly.  Note that all return
- * values from these two functions are NOT rounded.
- */
-void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
-                       gnc_numeric *discount, gnc_numeric *tax_value,
-                       GList **tax_values);
-
-void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
-                           const GncTaxTable *tax_table, gboolean tax_included,
-                           gnc_numeric discount, GncAmountType discount_type,
-                           GncDiscountHow discount_how, int SCU,
-                           /* return values */
-                           gnc_numeric *value, gnc_numeric *discount_value,
-                           GList **tax_values);
-
-/** @} */
-
-GncOrder * gncEntryGetOrder (const GncEntry *entry);
-GncInvoice * gncEntryGetInvoice (const GncEntry *entry);
-GncInvoice * gncEntryGetBill (const GncEntry *entry);
-
-/** Return a pointer to the instance gncEntry that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncEntry * gncEntryLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncEntry * gncEntryLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ENTRY, GncEntry);
-}
-
-gboolean gncEntryIsOpen (const GncEntry *entry);
-void gncEntryBeginEdit (GncEntry *entry);
-void gncEntryCommitEdit (GncEntry *entry);
-int gncEntryCompare (const GncEntry *a, const GncEntry *b);
-gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b);
-
-#define ENTRY_DATE			"date"
-#define ENTRY_DATE_ENTERED 	"date-entered"
-#define ENTRY_DESC			"desc"
-#define ENTRY_ACTION		"action"
-#define ENTRY_NOTES			"notes"
-#define ENTRY_QTY			"qty"
-
-#define ENTRY_IPRICE		"iprice"
-#define ENTRY_IACCT			"invoice-account"
-#define ENTRY_BACCT			"bill-account"
-#define ENTRY_BPRICE		"bprice"
-#define ENTRY_BILLABLE		"billable?"
-#define ENTRY_BILLTO		"bill-to"
-
-#define ENTRY_ORDER			"order"
-#define ENTRY_INVOICE		"invoice"
-#define ENTRY_BILL			"bill"
-
-#define ENTRY_INV_DISC_TYPE		"discount-type"
-#define ENTRY_INV_DISC_HOW		"discount-method"
-
-#define ENTRY_INV_TAXABLE	"invoice-taxable"
-#define ENTRY_BILL_TAXABLE	"bill-taxable"
-#define ENTRY_INV_TAX_INC	"invoice-tax-included"
-#define ENTRY_BILL_TAX_INC	"bill-tax-included"
-#define ENTRY_INV_DISCOUNT	"invoice-discount"
-#define ENTRY_BILL_PAY_TYPE "bill-payment-type"
-
-
-/* deprecated functions, should be removed */
-#define gncEntryGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-
-#endif /* GNC_ENTRY_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncEntryP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntryP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncEntryP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,64 +0,0 @@
-/********************************************************************\
- * gncEntryP.h -- the Core Busines Entry Interface                  *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_ENTRYP_H_
-#define GNC_ENTRYP_H_
-
-#include "gncEntry.h"
-
-gboolean gncEntryRegister (void);
-void gncEntrySetGUID (GncEntry *entry, const GncGUID *guid);
-void gncEntrySetOrder (GncEntry *entry, GncOrder *order);
-void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice);
-void gncEntrySetBill (GncEntry *entry, GncInvoice *bill);
-void gncEntrySetDirty (GncEntry *entry, gboolean dirty);
-
-
-/** The gncCloneEntry() routine makes a copy of the indicated
- *  entry, placing it in the indicated book.  It copies
- *  the whole kit-n-kaboodle.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncEntry * gncCloneEntry (GncEntry *from, QofBook *);
-
-/** The gncEntryObtainTwin() will find the 'twin' of the
- *  indicated entry in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneEntry()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book);
-
-#define gncEntrySetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-#endif /* GNC_ENTRYP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,2129 +0,0 @@
-/********************************************************************\
- * gncInvoice.c -- the Core Business Invoice                        *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001,2002,2006 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include "Transaction.h"
-#include "Account.h"
-#include "gncBillTermP.h"
-#include "gncEntry.h"
-#include "gncEntryP.h"
-#include "gncJobP.h"
-#include "gncInvoice.h"
-#include "gncInvoiceP.h"
-#include "gncOwnerP.h"
-
-struct _gncInvoice
-{
-    QofInstance inst;
-
-    char        *id;
-    char        *notes;
-    gboolean    active;
-
-    char        *billing_id;
-    char        *printname;
-    GncBillTerm *terms;
-    GList       *entries;
-    GList       *prices;
-    GncOwner    owner;
-    GncOwner    billto;
-    GncJob      *job;
-    Timespec    date_opened;
-    Timespec    date_posted;
-
-    gnc_numeric	to_charge_amount;
-
-    gnc_commodity * currency;
-
-    Account     *posted_acc;
-    Transaction *posted_txn;
-    GNCLot      *posted_lot;
-};
-
-struct _gncInvoiceClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME	GNC_ID_INVOICE
-
-#define GNC_INVOICE_ID		"gncInvoice"
-#define GNC_INVOICE_GUID	"invoice-guid"
-
-#define SET_STR(obj, member, str) { \
-	char * tmp; \
-	\
-	if (!safe_strcmp (member, str)) return; \
-	gncInvoiceBeginEdit (obj); \
-	tmp = CACHE_INSERT (str); \
-	CACHE_REMOVE (member); \
-	member = tmp; \
-	}
-
-static void mark_invoice (GncInvoice *invoice);
-static void
-mark_invoice (GncInvoice *invoice)
-{
-    qof_instance_set_dirty(&invoice->inst);
-    qof_event_gen (&invoice->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-QofBook * gncInvoiceGetBook(GncInvoice *x)
-{
-    return qof_instance_get_book(QOF_INSTANCE(x));
-}
-
-/* ================================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NOTES
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncInvoice, gnc_invoice, QOF_TYPE_INSTANCE);
-
-static void
-gnc_invoice_init(GncInvoice* inv)
-{
-}
-
-static void
-gnc_invoice_dispose(GObject *invp)
-{
-    G_OBJECT_CLASS(gnc_invoice_parent_class)->dispose(invp);
-}
-
-static void
-gnc_invoice_finalize(GObject* invp)
-{
-    G_OBJECT_CLASS(gnc_invoice_parent_class)->finalize(invp);
-}
-
-static void
-gnc_invoice_get_property (GObject         *object,
-                          guint            prop_id,
-                          GValue          *value,
-                          GParamSpec      *pspec)
-{
-    GncInvoice *inv;
-
-    g_return_if_fail(GNC_IS_INVOICE(object));
-
-    inv = GNC_INVOICE(object);
-    switch (prop_id)
-    {
-    case PROP_NOTES:
-        g_value_set_string(value, inv->notes);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_invoice_set_property (GObject         *object,
-                          guint            prop_id,
-                          const GValue          *value,
-                          GParamSpec      *pspec)
-{
-    GncInvoice *inv;
-
-    g_return_if_fail(GNC_IS_INVOICE(object));
-
-    inv = GNC_INVOICE(object);
-    switch (prop_id)
-    {
-    case PROP_NOTES:
-        gncInvoiceSetNotes(inv, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Returns a string representing this object */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncInvoice* inv;
-    QofInstance* owner;
-    gchar* s;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
-
-    inv = GNC_INVOICE(inst);
-    owner = qofOwnerGetOwner(&inv->owner);
-    if (owner != NULL)
-    {
-        gchar* display_name;
-
-        display_name = qof_instance_get_display_name(owner);
-        s = g_strdup_printf("Invoice %s (%s)", inv->id, display_name);
-        g_free(display_name);
-    }
-    else
-    {
-        s = g_strdup_printf("Invoice %s", inv->id);
-    }
-
-    return s;
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncInvoice* inv;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
-
-    inv = GNC_INVOICE(inst);
-
-    if (GNC_IS_BILLTERM(ref))
-    {
-        return (inv->terms == GNC_BILLTERM(ref));
-    }
-    else if (GNC_IS_JOB(ref))
-    {
-        return (inv->job == GNC_JOB(ref));
-    }
-    else if (GNC_IS_COMMODITY(ref))
-    {
-        return (inv->currency == GNC_COMMODITY(ref));
-    }
-    else if (GNC_IS_ACCOUNT(ref))
-    {
-        return (inv->posted_acc == GNC_ACCOUNT(ref));
-    }
-    else if (GNC_IS_TRANSACTION(ref))
-    {
-        return (inv->posted_txn == GNC_TRANSACTION(ref));
-    }
-    else if (GNC_IS_LOT(ref))
-    {
-        return (inv->posted_lot == GNC_LOT(ref));
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_JOB(ref) && !GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref)
-            && !GNC_IS_TRANSACTION(ref) && !GNC_IS_LOT(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_invoice_class_init (GncInvoiceClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_invoice_dispose;
-    gobject_class->finalize = gnc_invoice_finalize;
-    gobject_class->set_property = gnc_invoice_set_property;
-    gobject_class->get_property = gnc_invoice_get_property;
-
-    qof_class->get_display_name = impl_get_display_name;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NOTES,
-     g_param_spec_string ("notes",
-                          "Invoice Notes",
-                          "The invoice notes is an arbitrary string "
-                          "assigned by the user to provide notes regarding "
-                          "this invoice.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncInvoice *gncInvoiceCreate (QofBook *book)
-{
-    GncInvoice *invoice;
-
-    if (!book) return NULL;
-
-    invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
-    qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
-
-    invoice->id = CACHE_INSERT ("");
-    invoice->notes = CACHE_INSERT ("");
-    invoice->billing_id = CACHE_INSERT ("");
-
-    invoice->billto.type = GNC_OWNER_CUSTOMER;
-    invoice->active = TRUE;
-
-    invoice->to_charge_amount = gnc_numeric_zero();
-
-    qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
-
-    return invoice;
-}
-
-void gncInvoiceDestroy (GncInvoice *invoice)
-{
-    if (!invoice) return;
-    qof_instance_set_destroying(invoice, TRUE);
-    gncInvoiceCommitEdit (invoice);
-}
-
-static void gncInvoiceFree (GncInvoice *invoice)
-{
-    if (!invoice) return;
-
-    qof_event_gen (&invoice->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (invoice->id);
-    CACHE_REMOVE (invoice->notes);
-    CACHE_REMOVE (invoice->billing_id);
-    g_list_free (invoice->entries);
-    g_list_free (invoice->prices);
-
-    if (invoice->printname) g_free (invoice->printname);
-
-    if (invoice->terms)
-        gncBillTermDecRef (invoice->terms);
-
-    /* qof_instance_release (&invoice->inst); */
-    g_object_unref (invoice);
-}
-
-GncInvoice *
-gncCloneInvoice (GncInvoice *from, QofBook *book)
-{
-    GList *node;
-    GncInvoice *invoice;
-
-    if (!book) return NULL;
-
-    invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
-    qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
-
-    invoice->id = CACHE_INSERT (from->id);
-    invoice->notes = CACHE_INSERT (from->notes);
-    invoice->billing_id = CACHE_INSERT (from->billing_id);
-    invoice->active = from->active;
-
-    invoice->billto = gncCloneOwner (&from->billto, book);
-    invoice->owner = gncCloneOwner (&from->owner, book);
-    invoice->job = (GncJob*)gncJobObtainTwin (from->job, book);
-    invoice->terms = gncBillTermObtainTwin (from->terms, book);
-    gncBillTermIncRef (invoice->terms);
-
-
-    invoice->to_charge_amount = from->to_charge_amount;
-    invoice->printname = NULL; /* that's right, NULL. See below. */
-    invoice->date_opened = from->date_opened;
-    invoice->date_posted = from->date_posted;
-
-    invoice->currency = gnc_commodity_obtain_twin (from->currency, book);
-
-    invoice->entries = NULL;
-    for (node = g_list_last(from->entries); node; node = node->next)
-    {
-        GncEntry *entry = node->data;
-        entry = gncEntryObtainTwin (entry, book);
-        invoice->entries = g_list_prepend (invoice->entries, entry);
-    }
-
-    invoice->prices = NULL;
-    for (node = g_list_last(from->prices); node; node = node->next)
-    {
-        GNCPrice *price = node->data;
-        price = gnc_price_clone(price, book);
-        invoice->prices = g_list_prepend (invoice->prices, price);
-    }
-
-    /* XXX should probably be obtain-twin not lookup-twin */
-    invoice->posted_acc =
-        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->posted_acc), book));
-#if 0
-    XXX not done * /
-    Transaction * posted_txn;
-    GNCLot *	posted_lot;
-#endif
-
-    qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
-
-    return invoice;
-}
-
-GncInvoice *
-gncInvoiceObtainTwin (GncInvoice *from, QofBook *book)
-{
-    GncInvoice *invoice;
-    if (!book) return NULL;
-
-    invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!invoice)
-    {
-        invoice = gncCloneInvoice (from, book);
-    }
-
-    return invoice;
-}
-
-/* ================================================================== */
-/* Set Functions */
-
-void gncInvoiceSetID (GncInvoice *invoice, const char *id)
-{
-    if (!invoice || !id) return;
-    SET_STR (invoice, invoice->id, id);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner)
-{
-    if (!invoice || !owner) return;
-    if (gncOwnerEqual (&invoice->owner, owner)) return;
-    gncInvoiceBeginEdit (invoice);
-    gncOwnerCopy (owner, &invoice->owner);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-static void
-qofInvoiceSetOwner (GncInvoice *invoice, QofInstance *ent)
-{
-    if (!invoice || !ent)
-    {
-        return;
-    }
-    gncInvoiceBeginEdit (invoice);
-    qofOwnerSetEntity(&invoice->owner, ent);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-static void
-qofInvoiceSetBillTo (GncInvoice *invoice, QofInstance *ent)
-{
-    if (!invoice || !ent)
-    {
-        return;
-    }
-    gncInvoiceBeginEdit (invoice);
-    qofOwnerSetEntity(&invoice->billto, ent);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date)
-{
-    if (!invoice) return;
-    if (timespec_equal (&invoice->date_opened, &date)) return;
-    gncInvoiceBeginEdit (invoice);
-    invoice->date_opened = date;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date)
-{
-    if (!invoice) return;
-    if (timespec_equal (&invoice->date_posted, &date)) return;
-    gncInvoiceBeginEdit (invoice);
-    invoice->date_posted = date;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms)
-{
-    if (!invoice) return;
-    if (invoice->terms == terms) return;
-    gncInvoiceBeginEdit (invoice);
-    if (invoice->terms)
-        gncBillTermDecRef (invoice->terms);
-    invoice->terms = terms;
-    if (invoice->terms)
-        gncBillTermIncRef (invoice->terms);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id)
-{
-    if (!invoice) return;
-    SET_STR (invoice, invoice->billing_id, billing_id);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes)
-{
-    if (!invoice || !notes) return;
-    SET_STR (invoice, invoice->notes, notes);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
-{
-    if (!invoice) return;
-    if (invoice->active == active) return;
-    gncInvoiceBeginEdit (invoice);
-    invoice->active = active;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
-{
-    if (!invoice || !currency) return;
-    if (invoice->currency &&
-            gnc_commodity_equal (invoice->currency, currency))
-        return;
-    gncInvoiceBeginEdit (invoice);
-    invoice->currency = currency;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto)
-{
-    if (!invoice || !billto) return;
-    if (gncOwnerEqual (&invoice->billto, billto)) return;
-
-    gncInvoiceBeginEdit (invoice);
-    gncOwnerCopy (billto, &invoice->billto);
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount)
-{
-    if (!invoice) return;
-    if (gnc_numeric_equal (invoice->to_charge_amount, amount)) return;
-    gncInvoiceBeginEdit (invoice);
-    invoice->to_charge_amount = amount;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
-{
-    if (!invoice) return;
-    g_return_if_fail (invoice->posted_txn == NULL);
-
-    gncInvoiceBeginEdit (invoice);
-    invoice->posted_txn = txn;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot)
-{
-    if (!invoice) return;
-    g_return_if_fail (invoice->posted_lot == NULL);
-
-    gncInvoiceBeginEdit (invoice);
-    invoice->posted_lot = lot;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc)
-{
-    if (!invoice) return;
-    g_return_if_fail (invoice->posted_acc == NULL);
-
-    gncInvoiceBeginEdit (invoice);
-    invoice->posted_acc = acc;
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-}
-
-void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
-{
-    GncInvoice *old;
-
-    if (!invoice || !entry) return;
-
-    old = gncEntryGetInvoice (entry);
-    if (old == invoice) return;	/* I already own this one */
-    if (old) gncInvoiceRemoveEntry (old, entry);
-
-    gncEntrySetInvoice (entry, invoice);
-    invoice->entries = g_list_insert_sorted (invoice->entries, entry,
-                       (GCompareFunc)gncEntryCompare);
-    mark_invoice (invoice);
-}
-
-void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
-{
-    if (!invoice || !entry) return;
-
-    gncEntrySetInvoice (entry, NULL);
-    invoice->entries = g_list_remove (invoice->entries, entry);
-    mark_invoice (invoice);
-}
-
-void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
-{
-    if (!invoice || !price) return;
-
-    invoice->prices = g_list_prepend(invoice->prices, price);
-    mark_invoice (invoice);
-}
-
-void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price)
-{
-    if (!invoice || !price) return;
-
-    invoice->prices = g_list_remove (invoice->prices, price);
-    mark_invoice (invoice);
-}
-
-void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
-{
-    GncInvoice *old;
-
-    if (!bill || !entry) return;
-
-    old = gncEntryGetBill (entry);
-    if (old == bill) return;	/* I already own this one */
-    if (old) gncBillRemoveEntry (old, entry);
-
-    gncEntrySetBill (entry, bill);
-    bill->entries = g_list_insert_sorted (bill->entries, entry,
-                                          (GCompareFunc)gncEntryCompare);
-    mark_invoice (bill);
-}
-
-void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
-{
-    if (!bill || !entry) return;
-
-    gncEntrySetBill (entry, NULL);
-    bill->entries = g_list_remove (bill->entries, entry);
-    mark_invoice (bill);
-}
-
-void gncBillAddPrice (GncInvoice *bill, GNCPrice *price)
-{
-    if (!bill || !price) return;
-
-    bill->prices = g_list_prepend(bill->prices, price);
-    mark_invoice (bill);
-}
-
-void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price)
-{
-    if (!bill || !price) return;
-
-    bill->prices = g_list_remove (bill->prices, price);
-    mark_invoice (bill);
-}
-
-
-void gncInvoiceSortEntries (GncInvoice *invoice)
-{
-    if (!invoice) return;
-    invoice->entries = g_list_sort(invoice->entries,
-                                   (GCompareFunc)gncEntryCompare);
-    mark_invoice(invoice);
-}
-
-/* ================================================================== */
-/* Get Functions */
-
-const char * gncInvoiceGetID (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->id;
-}
-
-GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return &invoice->owner;
-}
-
-static QofInstance*
-qofInvoiceGetOwner (GncInvoice *invoice)
-{
-    GncOwner *owner;
-
-    if (!invoice)
-    {
-        return NULL;
-    }
-    owner = &invoice->owner;
-    return QOF_INSTANCE(owner);
-}
-
-static QofInstance*
-qofInvoiceGetBillTo (GncInvoice *invoice)
-{
-    GncOwner *billto;
-
-    if (!invoice)
-    {
-        return NULL;
-    }
-    billto = &invoice->billto;
-    return QOF_INSTANCE(billto);
-}
-
-Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!invoice) return ts;
-    return invoice->date_opened;
-}
-
-Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!invoice) return ts;
-    return invoice->date_posted;
-}
-
-Timespec gncInvoiceGetDateDue (const GncInvoice *invoice)
-{
-    Transaction *txn;
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!invoice) return ts;
-    txn = gncInvoiceGetPostedTxn (invoice);
-    if (!txn) return ts;
-    return xaccTransRetDateDueTS (txn);
-}
-
-GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->terms;
-}
-
-const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->billing_id;
-}
-
-const char * gncInvoiceGetNotes (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->notes;
-}
-
-GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice)
-{
-    GncOwner *owner;
-    g_return_val_if_fail (invoice, GNC_OWNER_NONE);
-
-    owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
-    return (gncOwnerGetType (owner));
-}
-
-static gnc_numeric
-gncInvoiceGetTotalInternal (GncInvoice *invoice, gboolean use_value,
-                            gboolean use_tax,
-                            gboolean use_payment_type, GncEntryPaymentType type)
-{
-    GList *node;
-    gnc_numeric total = gnc_numeric_zero();
-    gboolean reverse;
-
-    g_return_val_if_fail (invoice, total);
-
-    reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
-
-    for (node = gncInvoiceGetEntries(invoice); node; node = node->next)
-    {
-        GncEntry *entry = node->data;
-        gnc_numeric value, tax;
-
-        if (use_payment_type && gncEntryGetBillPayment (entry) != type)
-            continue;
-
-        gncEntryGetValue (entry, reverse, &value, NULL, &tax, NULL);
-
-        if (gnc_numeric_check (value) == GNC_ERROR_OK)
-        {
-            if (use_value)
-                total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-        }
-        else
-            g_warning ("bad value in our entry");
-
-        if (gnc_numeric_check (tax) == GNC_ERROR_OK)
-        {
-            if (use_tax)
-                total = gnc_numeric_add (total, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-        }
-        else
-            g_warning ("bad tax-value in our entry");
-    }
-    return total;
-}
-
-gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice)
-{
-    if (!invoice) return gnc_numeric_zero();
-    return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, FALSE, 0);
-}
-
-gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice)
-{
-    if (!invoice) return gnc_numeric_zero();
-    return gncInvoiceGetTotalInternal(invoice, TRUE, FALSE, FALSE, 0);
-}
-
-gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice)
-{
-    if (!invoice) return gnc_numeric_zero();
-    return gncInvoiceGetTotalInternal(invoice, FALSE, TRUE, FALSE, 0);
-}
-
-gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type)
-{
-    if (!invoice) return gnc_numeric_zero();
-    return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
-}
-
-const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type)
-{
-    switch (type)
-    {
-    case GNC_OWNER_CUSTOMER:
-        return _("Invoice");
-    case GNC_OWNER_VENDOR:
-        return _("Bill");
-    case GNC_OWNER_EMPLOYEE:
-        return _("Expense");
-    default:
-        return NULL;
-    }
-
-}
-
-const char * gncInvoiceGetType (GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return gncInvoiceGetTypeFromOwnerType (gncInvoiceGetOwnerType (invoice));
-}
-
-gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->currency;
-}
-
-GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return &invoice->billto;
-}
-
-GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->posted_lot;
-}
-
-Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->posted_txn;
-}
-
-Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->posted_acc;
-}
-
-gboolean gncInvoiceGetActive (const GncInvoice *invoice)
-{
-    if (!invoice) return FALSE;
-    return invoice->active;
-}
-
-
-gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
-{
-    if (!invoice) return gnc_numeric_zero();
-    return invoice->to_charge_amount;
-}
-
-EntryList * gncInvoiceGetEntries (GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->entries;
-}
-
-GList * gncInvoiceGetPrices(GncInvoice *invoice)
-{
-    if (!invoice) return NULL;
-    return invoice->prices;
-}
-
-GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity *commodity)
-{
-    GList *node = g_list_first(invoice->prices);
-
-    while (node != NULL)
-    {
-        GNCPrice *curr = (GNCPrice*)node->data;
-
-        if (gnc_commodity_equal(commodity, gnc_price_get_commodity(curr)))
-            return curr;
-
-        node = g_list_next(node);
-    }
-
-    return NULL;
-}
-
-static QofCollection*
-qofInvoiceGetEntries (GncInvoice *invoice)
-{
-    QofCollection *entry_coll;
-    GList         *list;
-    QofInstance     *entry;
-
-    entry_coll = qof_collection_new(GNC_ID_ENTRY);
-    for (list = gncInvoiceGetEntries(invoice); list != NULL; list = list->next)
-    {
-        entry = QOF_INSTANCE(list->data);
-        qof_collection_add_entity(entry_coll, entry);
-    }
-    return entry_coll;
-}
-
-static void
-qofInvoiceEntryCB (QofInstance *ent, gpointer user_data)
-{
-    GncInvoice *invoice;
-
-    invoice = (GncInvoice*)user_data;
-    if (!invoice || !ent)
-    {
-        return;
-    }
-    switch (gncInvoiceGetOwnerType (invoice))
-    {
-    case GNC_OWNER_VENDOR:
-    {
-        gncBillAddEntry (invoice, (GncEntry*) ent);
-        break;
-    }
-    default :
-    {
-        gncInvoiceAddEntry(invoice, (GncEntry*)ent);
-        break;
-    }
-    }
-}
-
-static void
-qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll)
-{
-    if (!entry_coll)
-    {
-        return;
-    }
-    if (0 == safe_strcmp(qof_collection_get_type(entry_coll), GNC_ID_ENTRY))
-    {
-        qof_collection_foreach(entry_coll, qofInvoiceEntryCB, invoice);
-    }
-}
-
-static GncJob*
-qofInvoiceGetJob (const GncInvoice *invoice)
-{
-    if (!invoice)
-    {
-        return NULL;
-    }
-    return invoice->job;
-}
-
-static void
-qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
-{
-    if (!invoice)
-    {
-        return;
-    }
-    invoice->job = job;
-}
-
-static void
-gncInvoiceDetachFromLot (GNCLot *lot)
-{
-    KvpFrame *kvp;
-
-    if (!lot) return;
-
-    kvp = gnc_lot_get_slots (lot);
-    kvp_frame_set_slot_path (kvp, NULL, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
-}
-
-static void
-gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-
-    if (!invoice || !lot)
-        return;
-
-    if (invoice->posted_lot) return;	/* Cannot reset invoice's lot */
-
-    kvp = gnc_lot_get_slots (lot);
-    value = kvp_value_new_guid (qof_instance_get_guid (QOF_INSTANCE(invoice)));
-    kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
-    kvp_value_delete (value);
-    gncInvoiceSetPostedLot (invoice, lot);
-}
-
-GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-    GncGUID *guid;
-    QofBook *book;
-
-    if (!lot) return NULL;
-
-    book = gnc_lot_get_book (lot);
-    kvp = gnc_lot_get_slots (lot);
-    value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
-    if (!value) return NULL;
-
-    guid = kvp_value_get_guid (value);
-    return gncInvoiceLookup(book, guid);
-}
-
-static void
-gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-
-    if (!invoice || !txn)
-        return;
-
-    if (invoice->posted_txn) return;	/* Cannot reset invoice's txn */
-
-    xaccTransBeginEdit (txn);
-    kvp = xaccTransGetSlots (txn);
-    value = kvp_value_new_guid (qof_instance_get_guid(QOF_INSTANCE(invoice)));
-    kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
-    kvp_value_delete (value);
-    xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
-    xaccTransCommitEdit (txn);
-    gncInvoiceSetPostedTxn (invoice, txn);
-}
-
-GncInvoice *
-gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-    GncGUID *guid;
-    QofBook *book;
-
-    if (!txn) return NULL;
-
-    book = xaccTransGetBook (txn);
-    kvp = xaccTransGetSlots (txn);
-    value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
-    if (!value) return NULL;
-
-    guid = kvp_value_get_guid (value);
-    return gncInvoiceLookup(book, guid);
-}
-
-struct lotmatch
-{
-    GncOwner *owner;
-    gboolean reverse;
-};
-
-static gboolean
-gnc_lot_match_owner_payment (GNCLot *lot, gpointer user_data)
-{
-    struct lotmatch *lm = user_data;
-    GncOwner owner_def, *owner;
-    gnc_numeric balance = gnc_lot_get_balance (lot);
-
-    /* Is this a payment lot */
-    if (gnc_numeric_positive_p (lm->reverse ? balance :
-                                gnc_numeric_neg (balance)))
-        return FALSE;
-
-    /* Is there an invoice attached? */
-    if (gncInvoiceGetInvoiceFromLot (lot))
-        return FALSE;
-
-    /* Is it ours? */
-    if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
-        return FALSE;
-    owner = gncOwnerGetEndOwner (&owner_def);
-
-    return gncOwnerEqual (owner, lm->owner);
-}
-
-Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
-                                       Timespec *post_date, Timespec *due_date,
-                                       const char * memo, gboolean accumulatesplits)
-{
-    Transaction *txn;
-    QofBook *book;
-    GNCLot *lot = NULL;
-    GList *iter;
-    GList *splitinfo = NULL;
-    gnc_numeric total;
-    gboolean reverse;
-    const char *name, *type;
-    char *lot_title;
-    Account *ccard_acct = NULL;
-    GncOwner *owner;
-
-    if (!invoice || !acc) return NULL;
-
-    gncInvoiceBeginEdit (invoice);
-    book = qof_instance_get_book(invoice);
-
-    /* Stabilize the Billing Terms of this invoice */
-    if (invoice->terms)
-        gncInvoiceSetTerms (invoice,
-                            gncBillTermReturnChild (invoice->terms, TRUE));
-
-    /* Figure out if we need to "reverse" the numbers. */
-    reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
-
-    /* Figure out if we need to separate out "credit-card" items */
-    owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
-    if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)
-        ccard_acct = gncEmployeeGetCCard (gncOwnerGetEmployee (owner));
-
-    /* Find an existing payment-lot for this owner */
-    {
-        LotList *lot_list;
-        struct lotmatch lm;
-
-        lm.reverse = reverse;
-        lm.owner = owner;
-
-        lot_list = xaccAccountFindOpenLots (acc, gnc_lot_match_owner_payment,
-                                            &lm, NULL);
-        if (lot_list)
-            lot = lot_list->data;
-
-        g_list_free (lot_list);
-    }
-
-    /* Create a new lot for this invoice, if we need to do so */
-    if (!lot)
-        lot = gnc_lot_new (book);
-    gnc_lot_begin_edit (lot);
-
-    type = gncInvoiceGetType (invoice);
-
-    /* Set the lot title */
-    lot_title = g_strdup_printf ("%s %s", type, gncInvoiceGetID (invoice));
-    gnc_lot_set_title (lot, lot_title);
-    g_free (lot_title);
-
-    /* Create a new transaction */
-    txn = xaccMallocTransaction (book);
-    xaccTransBeginEdit (txn);
-
-    name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
-
-    /* Set Transaction Description (Owner Name) , Num (invoice ID), Currency */
-    xaccTransSetDescription (txn, name ? name : "");
-    xaccTransSetNum (txn, gncInvoiceGetID (invoice));
-    xaccTransSetCurrency (txn, invoice->currency);
-
-    /* Entered and Posted at date */
-    xaccTransSetDateEnteredSecs (txn, time(NULL));
-    if (post_date)
-    {
-        xaccTransSetDatePostedTS (txn, post_date);
-        gncInvoiceSetDatePosted (invoice, *post_date);
-    }
-
-    if (due_date)
-        xaccTransSetDateDueTS (txn, due_date);
-
-    /* Iterate through the entries; sum up everything for each account.
-     * then create the appropriate splits in this txn.
-     */
-    total = gnc_numeric_zero();
-    for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
-    {
-        gnc_numeric value, tax;
-        GList *taxes;
-        GncEntry * entry = iter->data;
-        Account *this_acc;
-
-        /* Stabilize the TaxTable in this entry */
-        gncEntryBeginEdit (entry);
-        if (reverse)
-            gncEntrySetInvTaxTable
-            (entry, gncTaxTableReturnChild (gncEntryGetInvTaxTable (entry), TRUE));
-        else
-        {
-            gncEntrySetBillTaxTable
-            (entry, gncTaxTableReturnChild (gncEntryGetBillTaxTable (entry), TRUE));
-
-            /* If this is a bill, and the entry is billable, copy the price */
-            if (gncEntryGetBillable (entry))
-                gncEntrySetInvPrice (entry, gncEntryGetBillPrice (entry));
-        }
-        gncEntryCommitEdit (entry);
-
-        /* Obtain the Entry's Value and TaxValues */
-        gncEntryGetValue (entry, reverse, &value, NULL, &tax, &taxes);
-
-        /* add the value for the account split */
-        this_acc = (reverse ? gncEntryGetInvAccount (entry) :
-                    gncEntryGetBillAccount (entry));
-        if (this_acc)
-        {
-            if (gnc_numeric_check (value) == GNC_ERROR_OK)
-            {
-                if (accumulatesplits)
-                {
-                    splitinfo = gncAccountValueAdd (splitinfo, this_acc, value);
-                }
-                else
-                {
-                    Split *split;
-
-                    split = xaccMallocSplit (book);
-                    /* set action and memo? */
-
-                    xaccSplitSetMemo (split, gncEntryGetDescription (entry));
-                    xaccSplitSetAction (split, type);
-
-                    /* Need to insert this split into the account AND txn before
-                     * we set the Base Value.  Otherwise SetBaseValue complains
-                     * that we don't have an account and fails to set the value.
-                     */
-                    xaccAccountBeginEdit (this_acc);
-                    xaccAccountInsertSplit (this_acc, split);
-                    xaccAccountCommitEdit (this_acc);
-                    xaccTransAppendSplit (txn, split);
-
-                    if (gnc_commodity_equal(xaccAccountGetCommodity(this_acc), invoice->currency))
-                    {
-                        xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (value)
-                                                       : value),
-                                               invoice->currency);
-                    }
-                    else
-                    {
-                        /*need to do conversion */
-                        GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(this_acc));
-
-                        if (price == NULL)
-                        {
-                            /*This is an error, which shouldn't even be able to happen.
-                              We can't really do anything sensible about it, and this is
-                            		    a user-interface free zone so we can't try asking the user
-                              again either, have to return NULL*/
-                            return NULL;
-                        }
-                        else
-                        {
-                            gnc_numeric converted_amount;
-                            xaccSplitSetValue(split, (reverse ? gnc_numeric_neg(value) : value));
-                            converted_amount = gnc_numeric_div(value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
-                            printf("converting from %f to %f\n", gnc_numeric_to_double(value), gnc_numeric_to_double(converted_amount));
-                            xaccSplitSetAmount(split, reverse ? gnc_numeric_neg(converted_amount) : converted_amount);
-                        }
-                    }
-                }
-
-                /* If there is a credit-card account, and this is a CCard
-                 * payment type, the don't add it to the total, and instead
-                 * create a split to the CC Acct with a memo of the entry
-                 * description instead of the provided memo.  Note that the
-                 * value reversal is the same as the post account.
-                 *
-                 * Note: we don't have to worry about the tax values --
-                 * expense vouchers don't have them.
-                 */
-                if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD)
-                {
-                    Split *split;
-
-                    split = xaccMallocSplit (book);
-                    /* set action? */
-                    xaccSplitSetMemo (split, gncEntryGetDescription (entry));
-                    xaccSplitSetAction (split, type);
-                    xaccAccountBeginEdit (ccard_acct);
-                    xaccAccountInsertSplit (ccard_acct, split);
-                    xaccAccountCommitEdit (ccard_acct);
-                    xaccTransAppendSplit (txn, split);
-                    xaccSplitSetBaseValue (split, (reverse ? value : gnc_numeric_neg (value)),
-                                           invoice->currency);
-
-                }
-                else
-                    total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-
-            }
-            else
-                g_warning ("bad value in our entry");
-        }
-
-        /* now merge in the TaxValues */
-        splitinfo = gncAccountValueAddList (splitinfo, taxes);
-
-        /* ... and add the tax total */
-        if (gnc_numeric_check (tax) == GNC_ERROR_OK)
-            total = gnc_numeric_add (total, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-        else
-            g_warning ("bad tax in our entry");
-
-    } /* for */
-
-    /* Iterate through the splitinfo list and generate the splits */
-    for (iter = splitinfo; iter; iter = iter->next)
-    {
-        Split *split;
-        GncAccountValue *acc_val = iter->data;
-
-        split = xaccMallocSplit (book);
-        /* set action and memo? */
-
-        xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, type);
-
-        xaccAccountBeginEdit (acc_val->account);
-        xaccAccountInsertSplit (acc_val->account, split);
-        xaccAccountCommitEdit (acc_val->account);
-        xaccTransAppendSplit (txn, split);
-
-        if (gnc_commodity_equal(xaccAccountGetCommodity(acc_val->account), invoice->currency))
-        {
-            xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (acc_val->value)
-                                           : acc_val->value),
-                                   invoice->currency);
-        }
-        else
-        {
-            /*need to do conversion */
-            GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(acc_val->account));
-
-            if (price == NULL)
-            {
-                /*This is an error, which shouldn't even be able to happen.
-                  We can't really do anything sensible about it, and this is
-                  a user-interface free zone so we can't try asking the user
-                  again either, have to return NULL*/
-                return NULL;
-            }
-            else
-            {
-                gnc_numeric converted_amount;
-                xaccSplitSetValue(split, (reverse ? gnc_numeric_neg(acc_val->value) : acc_val->value));
-                converted_amount = gnc_numeric_div(acc_val->value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
-                printf("converting from %f to %f\n", gnc_numeric_to_double(acc_val->value), gnc_numeric_to_double(converted_amount));
-
-                xaccSplitSetAmount(split, reverse ? gnc_numeric_neg(converted_amount) : converted_amount);
-            }
-        }
-    }
-
-    /* If there is a ccard account, we may have an additional "to_card" payment.
-     * we should make that now..
-     */
-    if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount))
-    {
-        Split *split = xaccMallocSplit (book);
-
-        /* Set memo.  action? */
-        xaccSplitSetMemo (split, _("Extra to Charge Card"));
-        xaccSplitSetAction (split, type);
-
-        xaccAccountBeginEdit (ccard_acct);
-        xaccAccountInsertSplit (ccard_acct, split);
-        xaccAccountCommitEdit (ccard_acct);
-        xaccTransAppendSplit (txn, split);
-        xaccSplitSetBaseValue (split, (reverse ? invoice->to_charge_amount :
-                                       gnc_numeric_neg(invoice->to_charge_amount)),
-                               invoice->currency);
-
-        total = gnc_numeric_sub (total, invoice->to_charge_amount,
-                                 GNC_DENOM_AUTO, GNC_DENOM_LCD);
-    }
-
-    /* Now create the Posted split (which is negative -- it's a credit) */
-    {
-        Split *split = xaccMallocSplit (book);
-
-        /* Set action/memo */
-        xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, type);
-
-        xaccAccountBeginEdit (acc);
-        xaccAccountInsertSplit (acc, split);
-        xaccAccountCommitEdit (acc);
-        xaccTransAppendSplit (txn, split);
-        xaccSplitSetBaseValue (split, (reverse ? total : gnc_numeric_neg (total)),
-                               invoice->currency);
-
-        /* add this split to the lot */
-        gnc_lot_add_split (lot, split);
-    }
-
-    /* Now attach this invoice to the txn, lot, and account */
-    gncInvoiceAttachToLot (invoice, lot);
-    gncInvoiceAttachToTxn (invoice, txn);
-    gncInvoiceSetPostedAcc (invoice, acc);
-
-    xaccTransSetReadOnly (txn, _("Generated from an invoice.  Try unposting the invoice."));
-    xaccTransCommitEdit (txn);
-
-    gncAccountValueDestroy (splitinfo);
-
-    /* check the lot -- if we still look like a payment lot, then that
-     * means we need to create a balancing split and create a new payment
-     * lot for the next invoice
-     *
-     * we're looking for a positive balance for bill/AP, and a negative balance
-     * for invoice/AR.
-     * (because bill payments debit AP accounts and invoice payments
-     * credit AR accounts)
-     */
-    total = gnc_lot_get_balance (lot);
-
-    if ( (gnc_numeric_negative_p (total) && reverse) ||
-            (gnc_numeric_positive_p (total) && !reverse) )
-    {
-        Transaction *t2;
-        GNCLot *lot2;
-        Split *split;
-        /* Translators: This is the memo of an auto-created split */
-        char *memo2 = _("Automatic Payment Forward");
-        char *action2 = _("Auto Split");
-
-        t2 = xaccMallocTransaction (book);
-        lot2 = gnc_lot_new (book);
-        gnc_lot_begin_edit (lot2);
-        gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)),
-                             lot2);
-
-        xaccTransBeginEdit (t2);
-        xaccAccountBeginEdit (acc);
-
-        /* Set Transaction Description (Owner Name), Currency */
-        xaccTransSetDescription (t2, name ? name : "");
-        xaccTransSetCurrency (t2, invoice->currency);
-
-        /* Entered and Posted at date */
-        xaccTransSetDateEnteredSecs (t2, time(NULL));
-        if (post_date)
-            xaccTransSetDatePostedTS (t2, post_date);
-
-        /* Balance out this lot */
-        split = xaccMallocSplit (book);
-        xaccSplitSetMemo (split, memo2);
-        xaccSplitSetAction (split, action2);
-        xaccAccountInsertSplit (acc, split);
-        xaccTransAppendSplit (t2, split);
-        // the value of total used here is correct for both bill/AP and
-        // invoice/AR. See the comment before this if block
-        xaccSplitSetBaseValue (split, gnc_numeric_neg (total),
-                               invoice->currency);
-        gnc_lot_add_split (lot, split);
-
-        /* And apply the pre-payment to a new lot */
-        split = xaccMallocSplit (book);
-        xaccSplitSetMemo (split, memo2);
-        xaccSplitSetAction (split, action2);
-        xaccAccountInsertSplit (acc, split);
-        xaccTransAppendSplit (t2, split);
-        xaccSplitSetBaseValue (split, total, invoice->currency);
-        gnc_lot_add_split (lot2, split);
-
-        gnc_lot_commit_edit (lot2);
-        xaccTransCommitEdit (t2);
-        xaccAccountCommitEdit (acc);
-    }
-
-    gnc_lot_commit_edit (lot);
-    gncInvoiceCommitEdit (invoice);
-
-    return txn;
-}
-
-gboolean
-gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
-{
-    Transaction *txn;
-    GNCLot *lot;
-
-    if (!invoice) return FALSE;
-    if (!gncInvoiceIsPosted (invoice)) return FALSE;
-
-    txn = gncInvoiceGetPostedTxn (invoice);
-    g_return_val_if_fail (txn, FALSE);
-
-    lot = gncInvoiceGetPostedLot (invoice);
-    g_return_val_if_fail (lot, FALSE);
-
-    /* Destroy the Posted Transaction */
-    xaccTransClearReadOnly (txn);
-    xaccTransBeginEdit (txn);
-    xaccTransDestroy (txn);
-    xaccTransCommitEdit (txn);
-
-    /* Disconnect the lot from the invoice; re-attach to the invoice owner */
-    gncInvoiceDetachFromLot (lot);
-    gncOwnerAttachToLot (&invoice->owner, lot);
-
-    /* If the lot has no splits, then destroy it */
-    if (!gnc_lot_count_splits (lot))
-        gnc_lot_destroy (lot);
-
-    /* Clear out the invoice posted information */
-    gncInvoiceBeginEdit (invoice);
-
-    invoice->posted_acc = NULL;
-    invoice->posted_txn = NULL;
-    invoice->posted_lot = NULL;
-    invoice->date_posted.tv_sec = invoice->date_posted.tv_nsec = 0;
-
-    /* if we've been asked to reset the tax tables, then do so */
-    if (reset_tax_tables)
-    {
-        gboolean reverse = (gncInvoiceGetOwnerType(invoice) == GNC_OWNER_CUSTOMER);
-        GList *iter;
-
-        for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
-        {
-            GncEntry *entry = iter->data;
-
-            gncEntryBeginEdit(entry);
-            if (reverse)
-                gncEntrySetInvTaxTable(entry,
-                                       gncTaxTableGetParent(gncEntryGetInvTaxTable(entry)));
-            else
-                gncEntrySetBillTaxTable(entry,
-                                        gncTaxTableGetParent(gncEntryGetBillTaxTable(entry)));
-            gncEntryCommitEdit(entry);
-        }
-    }
-
-    mark_invoice (invoice);
-    gncInvoiceCommitEdit (invoice);
-
-    return TRUE;
-}
-
-static gboolean
-gnc_lot_match_invoice_owner (GNCLot *lot, gpointer user_data)
-{
-    GncOwner owner_def, *owner, *this_owner = user_data;
-    GncInvoice *invoice;
-
-    /* If this lot is not for this owner, then ignore it */
-    invoice = gncInvoiceGetInvoiceFromLot (lot);
-    if (invoice)
-    {
-        owner = gncInvoiceGetOwner (invoice);
-        owner = gncOwnerGetEndOwner (owner);
-    }
-    else
-    {
-        if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
-            return FALSE;
-        owner = gncOwnerGetEndOwner (&owner_def);
-    }
-
-    return gncOwnerEqual (owner, this_owner);
-}
-
-static gint
-gnc_lot_sort_func (GNCLot *a, GNCLot *b)
-{
-    GncInvoice *ia, *ib;
-    Timespec da, db;
-
-    ia = gncInvoiceGetInvoiceFromLot (a);
-    ib = gncInvoiceGetInvoiceFromLot (b);
-
-    da = gncInvoiceGetDateDue (ia);
-    db = gncInvoiceGetDateDue (ib);
-
-    return timespec_cmp (&da, &db);
-}
-
-/*
- * Apply a payment of "amount" for the owner, between the xfer_account
- * (bank or other asset) and the posted_account (A/R or A/P).
- *
- * XXX: yes, this should be in gncOwner, but all the other logic is
- * in gncInvoice...
- */
-Transaction *
-gncOwnerApplyPayment (GncOwner *owner, GncInvoice* invoice,
-                      Account *posted_acc, Account *xfer_acc,
-                      gnc_numeric amount, gnc_numeric exch, Timespec date,
-                      const char *memo, const char *num)
-{
-    QofBook *book;
-    Account *inv_posted_acc;
-    Transaction *txn;
-    Split *split;
-    GList *lot_list, *fifo = NULL;
-    GNCLot *lot, *inv_posted_lot = NULL, *prepay_lot = NULL;
-    GncInvoice *this_invoice;
-    const char *name;
-    gnc_commodity *commodity;
-    gnc_numeric split_amt;
-    gboolean reverse, inv_passed = TRUE;
-    gnc_numeric payment_value = amount;
-
-    /* Verify our arguments */
-    if (!owner || !posted_acc || !xfer_acc) return NULL;
-    g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
-
-    /* Compute the ancillary data */
-    book = gnc_account_get_book (posted_acc);
-    name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
-    commodity = gncOwnerGetCurrency (owner);
-    reverse = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER);
-
-    txn = xaccMallocTransaction (book);
-    xaccTransBeginEdit (txn);
-
-    /* Set up the transaction */
-    xaccTransSetDescription (txn, name ? name : "");
-    xaccTransSetNum (txn, num);
-    xaccTransSetCurrency (txn, commodity);
-    xaccTransSetDateEnteredSecs (txn, time(NULL));
-    xaccTransSetDatePostedTS (txn, &date);
-    xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT);
-
-
-    /* The split for the transfer account */
-    split = xaccMallocSplit (book);
-    xaccSplitSetMemo (split, memo);
-    xaccSplitSetAction (split, _("Payment"));
-    xaccAccountBeginEdit (xfer_acc);
-    xaccAccountInsertSplit (xfer_acc, split);
-    xaccAccountCommitEdit (xfer_acc);
-    xaccTransAppendSplit (txn, split);
-
-    if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity))
-    {
-        xaccSplitSetBaseValue (split, reverse ? amount :
-                               gnc_numeric_neg (amount), commodity);
-    }
-    else
-    {
-        /* Need to value the payment in terms of the owner commodity */
-        xaccSplitSetAmount(split, reverse ? amount : gnc_numeric_neg (amount));
-        payment_value = gnc_numeric_mul(amount, exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
-        xaccSplitSetValue(split, reverse ? payment_value : gnc_numeric_neg(payment_value));
-    }
-
-
-    /* Now, find all "open" lots in the posting account for this
-     * company and apply the payment on a FIFO basis.  Create
-     * a new split for each open lot until the payment is gone.
-     */
-
-    fifo = xaccAccountFindOpenLots (posted_acc, gnc_lot_match_invoice_owner,
-                                    owner,
-                                    (GCompareFunc)gnc_lot_sort_func);
-
-    /* Check if an invoice was passed in, and if so, does it match the
-     * account, and is it an open lot?  If so, put it at the beginning
-     * of the lot list fifo so we post to this invoice's lot first.
-     */
-    if (invoice)
-    {
-        inv_posted_acc = gncInvoiceGetPostedAcc(invoice);
-        inv_posted_lot = gncInvoiceGetPostedLot(invoice);
-        if (inv_posted_acc && inv_posted_lot &&
-                guid_equal(xaccAccountGetGUID(inv_posted_acc),
-                           xaccAccountGetGUID(posted_acc)) &&
-                !gnc_lot_is_closed(inv_posted_lot))
-        {
-            /* Put this invoice at the beginning of the FIFO */
-            fifo = g_list_prepend (fifo, inv_posted_lot);
-            inv_passed = FALSE;
-        }
-    }
-
-    xaccAccountBeginEdit (posted_acc);
-
-    /* Now iterate over the fifo until the payment is fully applied
-     * (or all the lots are paid)
-     */
-    for (lot_list = fifo; lot_list; lot_list = lot_list->next)
-    {
-        gnc_numeric balance;
-
-        lot = lot_list->data;
-
-        /* Skip this lot if it matches the invoice that was passed in and
-         * we've seen it already.  This way we post to it the first time
-         * (from the beginning of the lot-list) but not when we reach it
-         * the second time.
-         */
-        if (inv_posted_lot &&
-                guid_equal(qof_instance_get_guid(QOF_INSTANCE(lot)),
-                           qof_instance_get_guid(QOF_INSTANCE(inv_posted_lot))))
-        {
-            if (inv_passed)
-                continue;
-            else
-                inv_passed = TRUE;
-        }
-
-        balance = gnc_lot_get_balance (lot);
-
-        if (!reverse)
-            balance = gnc_numeric_neg (balance);
-
-        /* If the balance is "negative" then skip this lot.
-         * (just save the pre-payment lot for later)
-         */
-        if (gnc_numeric_negative_p (balance))
-        {
-            if (prepay_lot)
-            {
-                g_warning ("Multiple pre-payment lots are found.  Skipping.");
-            }
-            else
-            {
-                prepay_lot = lot;
-            }
-            continue;
-        }
-
-        /*
-         * If the payment_value <= the balance; we're done -- apply the payment_value.
-         * Otherwise, apply the balance, subtract that from the payment_value,
-         * and move on to the next one.
-         */
-        if (gnc_numeric_compare (payment_value, balance) <= 0)
-        {
-            /* payment_value <= balance */
-            split_amt = payment_value;
-        }
-        else
-        {
-            /* payment_value > balance */
-            split_amt = balance;
-        }
-
-        /* reduce the payment_value by split_amt */
-        payment_value = gnc_numeric_sub (payment_value, split_amt, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-
-        /* Create the split for this lot in the post account */
-        split = xaccMallocSplit (book);
-        xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, _("Payment"));
-        xaccAccountInsertSplit (posted_acc, split);
-        xaccTransAppendSplit (txn, split);
-        xaccSplitSetBaseValue (split, reverse ? gnc_numeric_neg (split_amt) :
-                               split_amt, commodity);
-        gnc_lot_add_split (lot, split);
-
-        /* Now send an event for the invoice so it gets updated as paid */
-        this_invoice = gncInvoiceGetInvoiceFromLot(lot);
-        if (this_invoice)
-            qof_event_gen (&this_invoice->inst, QOF_EVENT_MODIFY, NULL);
-
-        if (gnc_numeric_zero_p (payment_value))
-            break;
-    }
-
-    g_list_free (fifo);
-
-    /* If there is still money left here, then create a pre-payment lot */
-    if (gnc_numeric_positive_p (payment_value))
-    {
-        if (prepay_lot == NULL)
-        {
-            prepay_lot = gnc_lot_new (book);
-            gncOwnerAttachToLot (owner, prepay_lot);
-        }
-
-        split = xaccMallocSplit (book);
-        xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, _("Pre-Payment"));
-        xaccAccountInsertSplit (posted_acc, split);
-        xaccTransAppendSplit (txn, split);
-        xaccSplitSetBaseValue (split, reverse ? gnc_numeric_neg (payment_value) :
-                               payment_value, commodity);
-        gnc_lot_add_split (prepay_lot, split);
-    }
-
-    xaccAccountCommitEdit (posted_acc);
-
-    /* Commit this new transaction */
-    xaccTransCommitEdit (txn);
-
-    return txn;
-}
-
-static gboolean gncInvoiceDateExists (const Timespec *date)
-{
-    g_return_val_if_fail (date, FALSE);
-    if (date->tv_sec || date->tv_nsec) return TRUE;
-    return FALSE;
-}
-
-gboolean gncInvoiceIsPosted (const GncInvoice *invoice)
-{
-    if (!invoice) return FALSE;
-    return gncInvoiceDateExists (&(invoice->date_posted));
-}
-
-gboolean gncInvoiceIsPaid (const GncInvoice *invoice)
-{
-    if (!invoice) return FALSE;
-    if (!invoice->posted_lot) return FALSE;
-    return gnc_lot_is_closed(invoice->posted_lot);
-}
-
-/* ================================================================== */
-
-void gncInvoiceBeginEdit (GncInvoice *invoice)
-{
-    qof_begin_edit(&invoice->inst);
-}
-
-static void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("Invoice QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncInvoiceOnDone (QofInstance *invoice) { }
-
-static void invoice_free (QofInstance *inst)
-{
-    GncInvoice *invoice = (GncInvoice *) inst;
-    gncInvoiceFree (invoice);
-}
-
-void gncInvoiceCommitEdit (GncInvoice *invoice)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(invoice))) return;
-    qof_commit_edit_part2 (&invoice->inst, gncInvoiceOnError,
-                           gncInvoiceOnDone, invoice_free);
-}
-
-int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
-{
-    int compare;
-
-    if (a == b) return 0;
-    if (!a && b) return -1;
-    if (a && !b) return 1;
-
-    compare = safe_strcmp (a->id, b->id);
-    if (compare) return compare;
-
-    compare = timespec_cmp (&(a->date_opened), &(b->date_opened));
-    if (compare) return compare;
-
-    compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
-    if (compare) return compare;
-
-    return qof_instance_guid_compare(a, b);
-}
-
-gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_INVOICE(a), FALSE);
-    g_return_val_if_fail(GNC_IS_INVOICE(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->notes, b->notes) != 0)
-    {
-        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->billing_id, b->billing_id) != 0)
-    {
-        PWARN("Billing IDs differ: %s vs %s", a->billing_id, b->billing_id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->printname, b->printname) != 0)
-    {
-        PWARN("Printnames differ: %s vs %s", a->printname, b->printname);
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-    if (!gncBillTermEqual(a->terms, b->terms))
-    {
-        PWARN("Billterms differ");
-        return FALSE;
-    }
-
-    if (!gncJobEqual(a->job, b->job))
-    {
-        PWARN("Jobs differ");
-        return FALSE;
-    }
-
-    if (!gnc_commodity_equal(a->currency, b->currency))
-    {
-        PWARN("Currencies differ");
-        return FALSE;
-    }
-
-    if (!xaccAccountEqual(a->posted_acc, b->posted_acc, TRUE))
-    {
-        PWARN("Posted accounts differ");
-        return FALSE;
-    }
-
-    if (!xaccTransEqual(a->posted_txn, b->posted_txn, TRUE, TRUE, TRUE, FALSE))
-    {
-        PWARN("Posted tx differ");
-        return FALSE;
-    }
-
-#if 0
-    if (!gncLotEqual(a->posted_lot, b->posted_lot))
-    {
-        PWARN("Posted lots differ");
-        return FALSE;
-    }
-#endif
-
-    /* FIXME: Need real checks */
-#if 0
-    GList       *entries;
-    GList       *prices;
-    GncOwner    owner;
-    GncOwner    billto;
-    Timespec    date_opened;
-    Timespec    date_posted;
-
-    gnc_numeric	to_charge_amount;
-#endif
-
-    return TRUE;
-}
-
-/* ============================================================= */
-/* Package-Private functions */
-
-static const char * _gncInvoicePrintable (gpointer obj)
-{
-    GncInvoice *invoice = obj;
-
-    g_return_val_if_fail (invoice, NULL);
-
-    if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL)
-    {
-        if (invoice->printname) g_free (invoice->printname);
-
-        invoice->printname =
-            g_strdup_printf ("%s%s", invoice->id,
-                             gncInvoiceIsPosted (invoice) ? _(" (posted)") : "");
-    }
-
-    return invoice->printname;
-}
-
-static QofObject gncInvoiceDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Invoice",
-    DI(.create            = ) (gpointer)gncInvoiceCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) _gncInvoicePrintable,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-static void
-reg_lot (void)
-{
-    static QofParam params[] =
-    {
-        {
-            INVOICE_FROM_LOT, _GNC_MOD_NAME,
-            (QofAccessFunc)gncInvoiceGetInvoiceFromLot, NULL
-        },
-        { NULL },
-    };
-
-    qof_class_register (GNC_ID_LOT, NULL, params);
-}
-
-static void
-reg_txn (void)
-{
-    static QofParam params[] =
-    {
-        {
-            INVOICE_FROM_TXN, _GNC_MOD_NAME,
-            (QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL
-        },
-        { NULL },
-    };
-
-    qof_class_register (GNC_ID_TRANS, NULL, params);
-}
-
-gboolean gncInvoiceRegister (void)
-{
-    static QofParam params[] =
-    {
-        { INVOICE_ID,      QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID,     (QofSetterFunc)gncInvoiceSetID },
-        { INVOICE_OWNER,   GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
-        { INVOICE_OPENED,  QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
-        { INVOICE_DUE,     QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDateDue, NULL },
-        { INVOICE_POSTED,  QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
-        { INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL },
-        { INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid,    NULL },
-        { INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, (QofSetterFunc)gncInvoiceSetBillingID },
-        { INVOICE_NOTES,   QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes,   (QofSetterFunc)gncInvoiceSetNotes },
-        { INVOICE_ACC,     GNC_ID_ACCOUNT,  (QofAccessFunc)gncInvoiceGetPostedAcc, (QofSetterFunc)gncInvoiceSetPostedAcc },
-        { INVOICE_POST_TXN, GNC_ID_TRANS,   (QofAccessFunc)gncInvoiceGetPostedTxn, (QofSetterFunc)gncInvoiceSetPostedTxn },
-        { INVOICE_POST_LOT, GNC_ID_LOT,     (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
-        { INVOICE_TYPE,    QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType,    NULL },
-        { INVOICE_TERMS,   GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms,   (QofSetterFunc)gncInvoiceSetTerms },
-        { INVOICE_BILLTO,  GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL  },
-        { INVOICE_ENTRIES, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
-        { INVOICE_JOB,     GNC_ID_JOB,      (QofAccessFunc)qofInvoiceGetJob,     (QofSetterFunc)qofInvoiceSetJob },
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, (QofSetterFunc)gncInvoiceSetActive },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params);
-    reg_lot ();
-    reg_txn ();
-
-    /* Make the compiler happy... */
-    if (0)
-    {
-        qofInvoiceSetEntries(NULL, NULL);
-        qofInvoiceGetEntries(NULL);
-        qofInvoiceSetOwner(NULL, NULL);
-        qofInvoiceGetOwner(NULL);
-        qofInvoiceSetBillTo(NULL, NULL);
-        qofInvoiceGetBillTo(NULL);
-    }
-    if (!qof_choice_create(GNC_ID_INVOICE))
-    {
-        return FALSE;
-    }
-    return qof_object_register (&gncInvoiceDesc);
-}
-
-gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner)
-{
-    gint64 nextID;
-    switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
-    {
-    case GNC_OWNER_CUSTOMER:
-        nextID = qof_book_get_counter (book, "gncInvoice");
-        break;
-    case GNC_OWNER_VENDOR:
-        nextID = qof_book_get_counter (book, "gncBill");
-        break;
-    case GNC_OWNER_EMPLOYEE:
-        nextID = qof_book_get_counter (book, "gncExpVoucher");
-        break;
-    default:
-        nextID = qof_book_get_counter (book, _GNC_MOD_NAME);
-        break;
-    }
-    return nextID;
-}

Deleted: gnucash/trunk/src/business/business-core/gncInvoice.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncInvoice.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,231 +0,0 @@
-/********************************************************************\
- * gncInvoice.h -- the Core Business Invoice Interface              *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Invoice
-
-An invoice holds a list of entries, a pointer to the customer,
-and the job, the dates entered and posted, as well as the account,
-transaction and lot for the posted invoice.
-    @{ */
-/** @file gncInvoice.h
-    @brief  Business Invoice Interface
-    @author Copyright (C) 2001,2006 Derek Atkins <warlord at MIT.EDU>
-    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
-*/
-
-#ifndef GNC_INVOICE_H_
-#define GNC_INVOICE_H_
-
-struct _gncInvoice;
-typedef struct _gncInvoice GncInvoice;
-typedef struct _gncInvoiceClass GncInvoiceClass;
-
-#include "gncBillTerm.h"
-#include "gncEntry.h"
-#include "gncOwner.h"
-#include "gnc-lot.h"
-#include "qofbook.h"
-#include "qofbook.h"
-#include "gnc-pricedb.h"
-
-#define GNC_ID_INVOICE    "gncInvoice"
-
-/* --- type macros --- */
-#define GNC_TYPE_INVOICE            (gnc_invoice_get_type ())
-#define GNC_INVOICE(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_INVOICE, GncInvoice))
-#define GNC_INVOICE_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_INVOICE, GncInvoiceClass))
-#define GNC_IS_INVOICE(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_INVOICE))
-#define GNC_IS_INVOICE_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_INVOICE))
-#define GNC_INVOICE_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
-GType gnc_invoice_get_type(void);
-
-/** @name Create/Destroy Functions
- @{ */
-GncInvoice *gncInvoiceCreate (QofBook *book);
-void gncInvoiceDestroy (GncInvoice *invoice);
-/** @} */
-
-/** @name Set Functions
- @{ */
-void gncInvoiceSetID (GncInvoice *invoice, const char *id);
-void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
-void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date);
-void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date);
-void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms);
-void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id);
-void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
-void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency);
-void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
-void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
-void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
-/** @} */
-
-void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry);
-void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry);
-void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price);
-void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price);
-
-/** Call this function when adding an entry to a bill instead of an invoice */
-void gncBillAddEntry (GncInvoice *bill, GncEntry *entry);
-void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
-void gncBillAddPrice (GncInvoice *bill, GNCPrice *price);
-void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price);
-
-/** Call this function when an Entry is changed and you want to
-    re-sort the list of entries
-*/
-void gncInvoiceSortEntries (GncInvoice *invoice);
-
-/** @name Get Functions
- @{ */
-const char * gncInvoiceGetID (const GncInvoice *invoice);
-GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
-Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice);
-Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice);
-Timespec gncInvoiceGetDateDue (const GncInvoice *invoice);
-GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
-const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
-const char * gncInvoiceGetNotes (const GncInvoice *invoice);
-GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
-const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type);
-const char * gncInvoiceGetType (GncInvoice *invoice);
-gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
-GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
-gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
-gboolean gncInvoiceGetActive (const GncInvoice *invoice);
-
-GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
-Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
-Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
-/** @} */
-
-/** return the "total" amount of the invoice */
-gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice);
-gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type);
-gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice);
-gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice);
-
-typedef GList EntryList;
-EntryList * gncInvoiceGetEntries (GncInvoice *invoice);
-GList * gncInvoiceGetPrices(GncInvoice *invoice);
-GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity* commodity);
-
-/** Post this invoice to an account.  Returns the new Transaction
- * that is tied to this invoice.   The transaction is set with
- * the supplied posted date, due date, and memo.  The Transaction
- * description is set to the name of the company.
- */
-Transaction *
-gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
-                         Timespec *posted_date, Timespec *due_date,
-                         const char *memo, gboolean accumulatesplits);
-
-/**
- * UNpost this invoice.  This will destroy the posted transaction and
- * return the invoice to its unposted state.  It may leave empty lots
- * out there.  If reset_tax_tables is TRUE, then it will also revert
- * all the Tax Tables to the parent, which will potentially change the
- * total value of the invoice.  It may also leave some orphaned Tax
- * Table children.
- *
- * Returns TRUE if successful, FALSE if there is a problem.
- */
-gboolean
-gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
-
-/**
- * Apply a payment of "amount" for the owner, between the xfer_account
- * (bank or other asset) and the posted_account (A/R or A/P).  If the
- * caller supplies an (optional) invoice argument, then apply the
- * payment to that invoice first before any other invoice.
- *
- * XXX: yes, this should be in gncOwner, but all the other logic is
- * in gncInvoice...
- */
-Transaction *
-gncOwnerApplyPayment (GncOwner *owner, GncInvoice *invoice,
-                      Account *posted_acc, Account *xfer_acc,
-                      gnc_numeric amount, gnc_numeric exch, Timespec date,
-                      const char *memo, const char *num);
-
-
-/** Given a transaction, find and return the Invoice */
-GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
-
-/** Given a LOT, find and return the Invoice attached to the lot */
-GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
-
-/** Return a pointer to the instance gncInvoice that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncInvoice * gncInvoiceLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
-}
-
-void gncInvoiceBeginEdit (GncInvoice *invoice);
-void gncInvoiceCommitEdit (GncInvoice *invoice);
-int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
-gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b);
-gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
-gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
-
-#define INVOICE_ID	"id"
-#define INVOICE_OWNER	"owner"
-#define INVOICE_OPENED	"date_opened"
-#define INVOICE_POSTED	"date_posted"
-#define INVOICE_DUE	"date_due"
-#define INVOICE_IS_POSTED	"is_posted?"
-#define INVOICE_IS_PAID	"is_paid?"
-#define INVOICE_TERMS	"terms"
-#define INVOICE_BILLINGID	"billing_id"
-#define INVOICE_NOTES	"notes"
-#define INVOICE_ACC	"account"
-#define INVOICE_POST_TXN	"posted_txn"
-#define INVOICE_POST_LOT	"posted_lot"
-#define INVOICE_TYPE	"type"
-#define INVOICE_BILLTO	"bill-to"
-#define INVOICE_ENTRIES     "list_of_entries"
-#define INVOICE_JOB         "invoice_job"
-
-#define INVOICE_FROM_LOT	"invoice-from-lot"
-#define INVOICE_FROM_TXN	"invoice-from-txn"
-
-QofBook *gncInvoiceGetBook(GncInvoice *x);
-
-/** deprecated functions */
-#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-#define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
-#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G))
-
-#endif /* GNC_INVOICE_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncInvoiceP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoiceP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncInvoiceP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,68 +0,0 @@
-/********************************************************************\
- * gncInvoiceP.h -- the Core Busines Invoice Interface              *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_INVOICEP_H_
-#define GNC_INVOICEP_H_
-
-#include "gncInvoice.h"
-#include "Account.h"
-#include "Transaction.h"
-#include "gnc-lot.h"
-#include "gncOwner.h"
-
-gboolean gncInvoiceRegister (void);
-gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner);
-void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
-void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
-void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
-void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
-
-
-/** The gncCloneInvoice() routine makes a copy of the indicated
- *  invoice, placing it in the indicated book.  It copies
- *  the name, description, type, due-days, discount, etc.
- *  It also copies (as needed) both parents and children, so that
- *  the parent-child relationship is correctly mirrored in the
- *  clone.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *);
-
-/** The gncInvoiceObtainTwin() will find the 'twin' of the
- *  indicated invoice in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneInvoice()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book);
-#define gncInvoiceSetGUID(I,G) qof_instance_set_guid(QOF_INSTANCE(I),(G))
-#endif /* GNC_INVOICEP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncJob.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncJob.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,568 +0,0 @@
-/********************************************************************\
- * gncJob.c -- the Core Job Interface                               *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001, 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "gncInvoice.h"
-#include "gncJob.h"
-#include "gncJobP.h"
-#include "gncOwnerP.h"
-
-struct _gncJob
-{
-    QofInstance inst;
-    char *        id;
-    char *        name;
-    char *        desc;
-    GncOwner      owner;
-    gboolean      active;
-};
-
-struct _gncJobClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME        GNC_ID_JOB
-
-/* ================================================================== */
-/* misc inline functions */
-
-G_INLINE_FUNC void mark_job (GncJob *job);
-void mark_job (GncJob *job)
-{
-    qof_instance_set_dirty(&job->inst);
-    qof_event_gen (&job->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* ================================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncJob, gnc_job, QOF_TYPE_INSTANCE);
-
-static void
-gnc_job_init(GncJob* job)
-{
-}
-
-static void
-gnc_job_dispose(GObject *jobp)
-{
-    G_OBJECT_CLASS(gnc_job_parent_class)->dispose(jobp);
-}
-
-static void
-gnc_job_finalize(GObject* jobp)
-{
-    G_OBJECT_CLASS(gnc_job_parent_class)->finalize(jobp);
-}
-
-static void
-gnc_job_get_property (GObject         *object,
-                      guint            prop_id,
-                      GValue          *value,
-                      GParamSpec      *pspec)
-{
-    GncJob *job;
-
-    g_return_if_fail(GNC_IS_JOB(object));
-
-    job = GNC_JOB(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, job->name);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_job_set_property (GObject         *object,
-                      guint            prop_id,
-                      const GValue          *value,
-                      GParamSpec      *pspec)
-{
-    GncJob *job;
-
-    g_return_if_fail(GNC_IS_JOB(object));
-
-    job = GNC_JOB(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncJobSetName(job, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    /* Refers to nothing */
-    return NULL;
-}
-
-static void
-gnc_job_class_init (GncJobClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_job_dispose;
-    gobject_class->finalize = gnc_job_finalize;
-    gobject_class->set_property = gnc_job_set_property;
-    gobject_class->get_property = gnc_job_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = NULL;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "Job Name",
-                          "The job name is an arbitrary string "
-                          "assigned by the user.  It is intended to "
-                          "a short character string that is displayed "
-                          "by the GUI as the job mnemonic.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncJob *gncJobCreate (QofBook *book)
-{
-    GncJob *job;
-
-    if (!book) return NULL;
-
-    job = g_object_new (GNC_TYPE_JOB, NULL);
-    qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
-
-    job->id = CACHE_INSERT ("");
-    job->name = CACHE_INSERT ("");
-    job->desc = CACHE_INSERT ("");
-    job->active = TRUE;
-
-    /* GncOwner not initialized */
-    qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
-
-    return job;
-}
-
-GncJob *
-gncCloneJob (GncJob *from, QofBook *book)
-{
-    GncJob *job;
-
-    if (!book) return NULL;
-
-    job = g_object_new (GNC_TYPE_JOB, NULL);
-    qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&job->inst, &from->inst);
-
-    job->id = CACHE_INSERT (from->id);
-    job->name = CACHE_INSERT (from->name);
-    job->desc = CACHE_INSERT (from->desc);
-    job->active = from->active;
-
-    job->owner = gncCloneOwner(&from->owner, book);
-
-    qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
-
-    return job;
-}
-
-void gncJobDestroy (GncJob *job)
-{
-    if (!job) return;
-    qof_instance_set_destroying(job, TRUE);
-    gncJobCommitEdit (job);
-}
-
-static void gncJobFree (GncJob *job)
-{
-    if (!job) return;
-
-    qof_event_gen (&job->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (job->id);
-    CACHE_REMOVE (job->name);
-    CACHE_REMOVE (job->desc);
-
-    switch (gncOwnerGetType (&(job->owner)))
-    {
-    case GNC_OWNER_CUSTOMER:
-        gncCustomerRemoveJob (gncOwnerGetCustomer(&job->owner), job);
-        break;
-    case GNC_OWNER_VENDOR:
-        gncVendorRemoveJob (gncOwnerGetVendor(&job->owner), job);
-        break;
-    default:
-        break;
-    }
-
-    /* qof_instance_release (&job->inst); */
-    g_object_unref (job);
-}
-
-GncJob *
-gncJobObtainTwin (GncJob *from, QofBook *book)
-{
-    GncJob *job;
-    if (!from) return NULL;
-
-    job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!job)
-    {
-        job = gncCloneJob (from, book);
-    }
-    return job;
-}
-
-/* ================================================================== */
-/* Set Functions */
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncJobBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-void gncJobSetID (GncJob *job, const char *id)
-{
-    if (!job) return;
-    if (!id) return;
-    SET_STR(job, job->id, id);
-    mark_job (job);
-    gncJobCommitEdit (job);
-}
-
-void gncJobSetName (GncJob *job, const char *name)
-{
-    if (!job) return;
-    if (!name) return;
-    SET_STR(job, job->name, name);
-    mark_job (job);
-    gncJobCommitEdit (job);
-}
-
-void gncJobSetReference (GncJob *job, const char *desc)
-{
-    if (!job) return;
-    if (!desc) return;
-    SET_STR(job, job->desc, desc);
-    mark_job (job);
-    gncJobCommitEdit (job);
-}
-
-void gncJobSetOwner (GncJob *job, GncOwner *owner)
-{
-    if (!job) return;
-    if (!owner) return;
-    if (gncOwnerEqual (owner, &(job->owner))) return;
-
-    switch (gncOwnerGetType (owner))
-    {
-    case GNC_OWNER_CUSTOMER:
-    case GNC_OWNER_VENDOR:
-        break;
-    default:
-        PERR("Unsupported Owner type: %d", gncOwnerGetType(owner));
-        return;
-    }
-
-    gncJobBeginEdit (job);
-
-    switch (gncOwnerGetType (&(job->owner)))
-    {
-    case GNC_OWNER_CUSTOMER:
-        gncCustomerRemoveJob (gncOwnerGetCustomer(&job->owner), job);
-        break;
-    case GNC_OWNER_VENDOR:
-        gncVendorRemoveJob (gncOwnerGetVendor(&job->owner), job);
-        break;
-    default:
-        break;
-    }
-
-    gncOwnerCopy (owner, &(job->owner));
-
-    switch (gncOwnerGetType (&(job->owner)))
-    {
-    case GNC_OWNER_CUSTOMER:
-        gncCustomerAddJob (gncOwnerGetCustomer(&job->owner), job);
-        break;
-    case GNC_OWNER_VENDOR:
-        gncVendorAddJob (gncOwnerGetVendor(&job->owner), job);
-        break;
-    default:
-        break;
-    }
-
-    mark_job (job);
-    gncJobCommitEdit (job);
-}
-
-void gncJobSetActive (GncJob *job, gboolean active)
-{
-    if (!job) return;
-    if (active == job->active) return;
-    gncJobBeginEdit (job);
-    job->active = active;
-    mark_job (job);
-    gncJobCommitEdit (job);
-}
-
-static void
-qofJobSetOwner (GncJob *job, QofInstance *ent)
-{
-    if (!job || !ent)
-    {
-        return;
-    }
-    qof_begin_edit(&job->inst);
-    qofOwnerSetEntity(&job->owner, ent);
-    mark_job (job);
-    qof_commit_edit(&job->inst);
-}
-
-void gncJobBeginEdit (GncJob *job)
-{
-    qof_begin_edit(&job->inst);
-}
-
-static void gncJobOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("Job QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void job_free (QofInstance *inst)
-{
-    GncJob *job = (GncJob *)inst;
-    gncJobFree (job);
-}
-
-static void gncJobOnDone (QofInstance *qof) { }
-
-void gncJobCommitEdit (GncJob *job)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(job))) return;
-    qof_commit_edit_part2 (&job->inst, gncJobOnError,
-                           gncJobOnDone, job_free);
-}
-
-/* ================================================================== */
-/* Get Functions */
-
-const char * gncJobGetID (const GncJob *job)
-{
-    if (!job) return NULL;
-    return job->id;
-}
-
-const char * gncJobGetName (const GncJob *job)
-{
-    if (!job) return NULL;
-    return job->name;
-}
-
-const char * gncJobGetReference (const GncJob *job)
-{
-    if (!job) return NULL;
-    return job->desc;
-}
-
-GncOwner * gncJobGetOwner (GncJob *job)
-{
-    if (!job) return NULL;
-    return &(job->owner);
-}
-
-gboolean gncJobGetActive (const GncJob *job)
-{
-    if (!job) return FALSE;
-    return job->active;
-}
-
-static QofInstance*
-qofJobGetOwner (GncJob *job)
-{
-    if (!job)
-    {
-        return NULL;
-    }
-    return QOF_INSTANCE(qofOwnerGetOwner(&job->owner));
-}
-
-/* Other functions */
-
-int gncJobCompare (const GncJob * a, const GncJob *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    return (safe_strcmp(a->id, b->id));
-}
-
-gboolean gncJobEqual(const GncJob * a, const GncJob *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
-    g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("Names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->desc, b->desc) != 0)
-    {
-        PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-    /* FIXME: Need real tests */
-#if 0
-    GncOwner      owner;
-#endif
-
-    return TRUE;
-}
-
-/* ================================================================== */
-/* Package-Private functions */
-
-static const char * _gncJobPrintable (gpointer item)
-{
-    GncJob *c;
-    if (!item) return NULL;
-    c = item;
-    return c->name;
-}
-
-static QofObject gncJobDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Job",
-    DI(.create            = ) (gpointer)gncJobCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) _gncJobPrintable,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncJobRegister (void)
-{
-    static QofParam params[] =
-    {
-        { JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, (QofSetterFunc)gncJobSetID },
-        { JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, (QofSetterFunc)gncJobSetName },
-        { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive },
-        { JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, (QofSetterFunc)gncJobSetReference },
-#ifdef GNUCASH_MAJOR_VERSION
-        { JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL },
-#else
-        { JOB_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofJobGetOwner, (QofSetterFunc)qofJobSetOwner },
-#endif
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    if (!qof_choice_create(GNC_ID_JOB))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_JOB, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
-#ifdef GNUCASH_MAJOR_VERSION
-    qofJobGetOwner(NULL);
-    qofJobSetOwner(NULL, NULL);
-#endif
-    return qof_object_register (&gncJobDesc);
-}
-
-gint64 gncJobNextID (QofBook *book)
-{
-    return qof_book_get_counter (book, _GNC_MOD_NAME);
-}

Deleted: gnucash/trunk/src/business/business-core/gncJob.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncJob.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,118 +0,0 @@
-/********************************************************************\
- * gncJob.h -- the Core Job Interface                               *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Job
-    @{ */
-/** @file gncJob.h
-    @brief  Job Interface
-    @author Copyright (C) 2001, 2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_JOB_H_
-#define GNC_JOB_H_
-
-typedef struct _gncJob GncJob;
-typedef struct _gncJobClass GncJobClass;
-
-#include "gncAddress.h"
-#include "gncOwner.h"
-
-#define GNC_ID_JOB "gncJob"
-
-/* --- type macros --- */
-#define GNC_TYPE_JOB            (gnc_job_get_type ())
-#define GNC_JOB(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_JOB, GncJob))
-#define GNC_JOB_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_JOB, GncJobClass))
-#define GNC_IS_JOB(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_JOB))
-#define GNC_IS_JOB_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_JOB))
-#define GNC_JOB_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_JOB, GncJobClass))
-GType gnc_job_get_type(void);
-
-/* Create/Destroy Functions */
-
-GncJob *gncJobCreate (QofBook *book);
-void gncJobDestroy (GncJob *job);
-
-/** \name Set Functions
-@{
-*/
-
-void gncJobSetID (GncJob *job, const char *id);
-void gncJobSetName (GncJob *job, const char *jobname);
-void gncJobSetReference (GncJob *job, const char *owner_reference);
-void gncJobSetOwner (GncJob *job, GncOwner *owner);
-void gncJobSetActive (GncJob *job, gboolean active);
-
-/** @} */
-void gncJobBeginEdit (GncJob *job);
-void gncJobCommitEdit (GncJob *job);
-
-/** \name Get Functions
-@{
-*/
-
-const char * gncJobGetID (const GncJob *job);
-const char * gncJobGetName (const GncJob *job);
-const char * gncJobGetReference (const GncJob *job);
-GncOwner * gncJobGetOwner (GncJob *job);
-
-/** @} */
-gboolean gncJobGetActive (const GncJob *job);
-
-/** Return a pointer to the instance gncJob that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncJob * gncJobLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncJob * gncJobLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_JOB, GncJob);
-}
-
-/* Other functions */
-
-int gncJobCompare (const GncJob *a, const GncJob *b);
-gboolean gncJobEqual(const GncJob *a, const GncJob *b);
-
-#define JOB_ID		"id"
-#define JOB_NAME	"name"
-#define JOB_REFERENCE	"reference"
-#define JOB_OWNER	"owner"
-#define Q_JOB_OWNER "owner_collection"
-#define JOB_ACTIVE	"active"
-
-/** deprecated functions */
-#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
-#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-#define gncJobRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
-#define gncJobLookupDirect(G,B) gncJobLookup((B),&(G))
-
-#endif /* GNC_JOB_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncJobP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncJobP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncJobP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,58 +0,0 @@
-/********************************************************************\
- * gncJobP.h -- the Core Job Interface                              *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_JOBP_H_
-#define GNC_JOBP_H_
-
-#include "gncJob.h"
-
-gboolean gncJobRegister (void);
-gint64 gncJobNextID (QofBook *book);
-
-/** The gncCloneTaxTable() routine makes a copy of the indicated
- *  tax table, placing it in the indicated book.  It copies
- *  the id, name description and owner.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-GncJob * gncCloneJob (GncJob *from, QofBook *book);
-
-/** The gncJobObtainTwin() will find the 'twin' of the
- *  indicated job in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneJob()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncJob * gncJobObtainTwin (GncJob *from, QofBook *book);
-
-#define gncJobSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-#endif /* GNC_JOBP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncOrder.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOrder.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,610 +0,0 @@
-/********************************************************************\
- * gncOrder.c -- the Core Business Order                            *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001,2002 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include "gncEntry.h"
-#include "gncEntryP.h"
-#include "gncOrder.h"
-#include "gncOrderP.h"
-#include "gncOwner.h"
-#include "gncOwnerP.h"
-
-struct _gncOrder
-{
-    QofInstance inst;
-
-    char *	id;
-    char *	notes;
-    gboolean 	active;
-
-    char *	reference;
-    char *	printname;
-    GncOwner	owner;
-    GList *	entries;
-    Timespec 	opened;
-    Timespec 	closed;
-};
-
-struct _gncOrderClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME	GNC_ID_ORDER
-
-#define SET_STR(obj, member, str) { \
-	char * tmp; \
-	\
-	if (!safe_strcmp (member, str)) return; \
-	gncOrderBeginEdit (obj); \
-	tmp = CACHE_INSERT (str); \
-	CACHE_REMOVE (member); \
-	member = tmp; \
-	}
-
-G_INLINE_FUNC void mark_order (GncOrder *order);
-void mark_order (GncOrder *order)
-{
-    qof_instance_set_dirty(&order->inst);
-    qof_event_gen (&order->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* =============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NOTES
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncOrder, gnc_order, QOF_TYPE_INSTANCE);
-
-static void
-gnc_order_init(GncOrder* order)
-{
-}
-
-static void
-gnc_order_dispose(GObject *orderp)
-{
-    G_OBJECT_CLASS(gnc_order_parent_class)->dispose(orderp);
-}
-
-static void
-gnc_order_finalize(GObject* orderp)
-{
-    G_OBJECT_CLASS(gnc_order_parent_class)->dispose(orderp);
-}
-
-static void
-gnc_order_get_property (GObject         *object,
-                        guint            prop_id,
-                        GValue          *value,
-                        GParamSpec      *pspec)
-{
-    GncOrder *order;
-
-    g_return_if_fail(GNC_IS_ORDER(object));
-
-    order = GNC_ORDER(object);
-    switch (prop_id)
-    {
-    case PROP_NOTES:
-        g_value_set_string(value, order->notes);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_order_set_property (GObject         *object,
-                        guint            prop_id,
-                        const GValue          *value,
-                        GParamSpec      *pspec)
-{
-    GncOrder *order;
-
-    g_return_if_fail(GNC_IS_ORDER(object));
-
-    order = GNC_ORDER(object);
-    switch (prop_id)
-    {
-    case PROP_NOTES:
-        gncOrderSetNotes(order, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    /* Refers to nothing */
-    return NULL;
-}
-
-static void
-gnc_order_class_init (GncOrderClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_order_dispose;
-    gobject_class->finalize = gnc_order_finalize;
-    gobject_class->set_property = gnc_order_set_property;
-    gobject_class->get_property = gnc_order_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = NULL;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NOTES,
-     g_param_spec_string ("name",
-                          "Order Notes",
-                          "The order notes is an arbitrary string "
-                          "assigned by the user to provide notes about "
-                          "this order.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncOrder *gncOrderCreate (QofBook *book)
-{
-    GncOrder *order;
-
-    if (!book) return NULL;
-
-    order = g_object_new (GNC_TYPE_ORDER, NULL);
-    qof_instance_init_data (&order->inst, _GNC_MOD_NAME, book);
-
-    order->id = CACHE_INSERT ("");
-    order->notes = CACHE_INSERT ("");
-    order->reference = CACHE_INSERT ("");
-
-    order->active = TRUE;
-
-    qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
-
-    return order;
-}
-
-void gncOrderDestroy (GncOrder *order)
-{
-    if (!order) return;
-    qof_instance_set_destroying(order, TRUE);
-    gncOrderCommitEdit (order);
-}
-
-static void gncOrderFree (GncOrder *order)
-{
-    if (!order) return;
-
-    qof_event_gen (&order->inst, QOF_EVENT_DESTROY, NULL);
-
-    g_list_free (order->entries);
-    CACHE_REMOVE (order->id);
-    CACHE_REMOVE (order->notes);
-    CACHE_REMOVE (order->reference);
-
-    if (order->printname) g_free (order->printname);
-
-    /* qof_instance_release (&order->inst); */
-    g_object_unref (order);
-}
-
-GncOrder *
-gncCloneOrder (GncOrder *from, QofBook *book)
-{
-    GList *node;
-    GncOrder *order;
-
-    if (!book) return NULL;
-
-    order = g_object_new (GNC_TYPE_ORDER, NULL);
-    qof_instance_init_data (&order->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&order->inst, &from->inst);
-
-    order->id = CACHE_INSERT (from->id);
-    order->notes = CACHE_INSERT (from->notes);
-    order->reference = CACHE_INSERT (from->reference);
-
-    order->active = from->active;
-    order->printname = NULL; /* yes, null, that's right */
-    order->opened = from->opened;
-    order->closed = from->closed;
-
-    order->owner = gncCloneOwner (&from->owner, book);
-
-    order->entries = NULL;
-    for (node = g_list_last(from->entries); node; node = node->prev)
-    {
-        GncEntry *entry = node->data;
-        entry = gncEntryObtainTwin (entry, book);
-        order->entries = g_list_prepend (order->entries, entry);
-    }
-
-    qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
-
-    return order;
-}
-
-GncOrder *
-gncOrderObtainTwin (GncOrder *from, QofBook *book)
-{
-    GncOrder *order;
-    if (!book) return NULL;
-
-    order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!order)
-    {
-        order = gncCloneOrder (from, book);
-    }
-
-    return order;
-}
-
-/* =============================================================== */
-/* Set Functions */
-
-void gncOrderSetID (GncOrder *order, const char *id)
-{
-    if (!order || !id) return;
-    SET_STR (order, order->id, id);
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetOwner (GncOrder *order, GncOwner *owner)
-{
-    if (!order || !owner) return;
-    if (gncOwnerEqual (&order->owner, owner)) return;
-
-    gncOrderBeginEdit (order);
-    gncOwnerCopy (owner, &order->owner);
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetDateOpened (GncOrder *order, Timespec date)
-{
-    if (!order) return;
-    if (timespec_equal (&order->opened, &date)) return;
-    gncOrderBeginEdit (order);
-    order->opened = date;
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetDateClosed (GncOrder *order, Timespec date)
-{
-    if (!order) return;
-    if (timespec_equal (&order->closed, &date)) return;
-    gncOrderBeginEdit (order);
-    order->closed = date;
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetNotes (GncOrder *order, const char *notes)
-{
-    if (!order || !notes) return;
-    SET_STR (order, order->notes, notes);
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetReference (GncOrder *order, const char *reference)
-{
-    if (!order || !reference) return;
-    SET_STR (order, order->reference, reference);
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-void gncOrderSetActive (GncOrder *order, gboolean active)
-{
-    if (!order) return;
-    if (order->active == active) return;
-    gncOrderBeginEdit (order);
-    order->active = active;
-    mark_order (order);
-    gncOrderCommitEdit (order);
-}
-
-/* =============================================================== */
-/* Add an Entry to the Order */
-void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
-{
-    GncOrder *old;
-
-    if (!order || !entry) return;
-
-    old = gncEntryGetOrder (entry);
-    if (old == order) return;			/* I already own it */
-    if (old) gncOrderRemoveEntry (old, entry);
-
-    order->entries = g_list_insert_sorted (order->entries, entry,
-                                           (GCompareFunc)gncEntryCompare);
-
-    /* This will send out an event -- make sure we're attached */
-    gncEntrySetOrder (entry, order);
-    mark_order (order);
-}
-
-void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
-{
-    if (!order || !entry) return;
-
-    gncEntrySetOrder (entry, NULL);
-    order->entries = g_list_remove (order->entries, entry);
-    mark_order (order);
-}
-
-/* Get Functions */
-
-const char * gncOrderGetID (const GncOrder *order)
-{
-    if (!order) return NULL;
-    return order->id;
-}
-
-GncOwner * gncOrderGetOwner (GncOrder *order)
-{
-    if (!order) return NULL;
-    return &order->owner;
-}
-
-Timespec gncOrderGetDateOpened (const GncOrder *order)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!order) return ts;
-    return order->opened;
-}
-
-Timespec gncOrderGetDateClosed (const GncOrder *order)
-{
-    Timespec ts;
-    ts.tv_sec = 0;
-    ts.tv_nsec = 0;
-    if (!order) return ts;
-    return order->closed;
-}
-
-const char * gncOrderGetNotes (const GncOrder *order)
-{
-    if (!order) return NULL;
-    return order->notes;
-}
-
-const char * gncOrderGetReference (const GncOrder *order)
-{
-    if (!order) return NULL;
-    return order->reference;
-}
-
-gboolean gncOrderGetActive (const GncOrder *order)
-{
-    if (!order) return FALSE;
-    return order->active;
-}
-
-/* Get the list Entries */
-GList * gncOrderGetEntries (GncOrder *order)
-{
-    if (!order) return NULL;
-    return order->entries;
-}
-
-gboolean gncOrderIsClosed (const GncOrder *order)
-{
-    if (!order) return FALSE;
-    if (order->closed.tv_sec || order->closed.tv_nsec) return TRUE;
-    return FALSE;
-}
-
-/* =============================================================== */
-
-void gncOrderBeginEdit (GncOrder *order)
-{
-    qof_begin_edit(&order->inst);
-}
-
-static void gncOrderOnError (QofInstance *order, QofBackendError errcode)
-{
-    PERR("Order QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncOrderOnDone (QofInstance *order) {}
-
-static void order_free (QofInstance *inst)
-{
-    GncOrder *order = (GncOrder *) inst;
-    gncOrderFree (order);
-}
-
-void gncOrderCommitEdit (GncOrder *order)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(order))) return;
-    qof_commit_edit_part2 (&order->inst, gncOrderOnError,
-                           gncOrderOnDone, order_free);
-}
-
-int gncOrderCompare (const GncOrder *a, const GncOrder *b)
-{
-    int compare;
-
-    if (a == b) return 0;
-    if (!a && b) return -1;
-    if (a && !b) return 1;
-
-    compare = safe_strcmp (a->id, b->id);
-    if (compare) return compare;
-
-    compare = timespec_cmp (&(a->opened), &(b->opened));
-    if (compare) return compare;
-
-    compare = timespec_cmp (&(a->closed), &(b->closed));
-    if (compare) return compare;
-
-    return qof_instance_guid_compare(a, b);
-}
-
-gboolean gncOrderEqual(const GncOrder * a, const GncOrder *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_ORDER(a), FALSE);
-    g_return_val_if_fail(GNC_IS_ORDER(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->notes, b->notes) != 0)
-    {
-        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->reference, b->reference) != 0)
-    {
-        PWARN("References differ: %s vs %s", a->reference, b->reference);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->printname, b->printname) != 0)
-    {
-        PWARN("printnames differ: %s vs %s", a->printname, b->printname);
-        return FALSE;
-    }
-
-    /* FIXME: Need real tests */
-#if 0
-    GncOwner	owner;
-    GList *	entries;
-    Timespec 	opened;
-    Timespec 	closed;
-#endif
-
-    return TRUE;
-}
-
-/* =========================================================== */
-/* Package-Private functions */
-
-static const char *
-_gncOrderPrintable (gpointer obj)
-{
-    GncOrder *order = obj;
-
-    g_return_val_if_fail (order, NULL);
-
-    if (qof_instance_get_dirty_flag(order) || order->printname == NULL)
-    {
-        if (order->printname) g_free (order->printname);
-
-        order->printname =
-            g_strdup_printf ("%s%s", order->id,
-                             gncOrderIsClosed (order) ? _(" (closed)") : "");
-    }
-
-    return order->printname;
-}
-
-static QofObject gncOrderDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Order",
-    DI(.create            = ) (gpointer)gncOrderCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) _gncOrderPrintable,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncOrderRegister (void)
-{
-    static QofParam params[] =
-    {
-        { ORDER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetID, (QofSetterFunc)gncOrderSetID },
-        { ORDER_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetReference, (QofSetterFunc)gncOrderSetReference },
-        { ORDER_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncOrderGetOwner, (QofSetterFunc)gncOrderSetOwner },
-        { ORDER_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateOpened, (QofSetterFunc)gncOrderSetDateOpened },
-        { ORDER_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed, NULL },
-        { ORDER_CLOSED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateClosed, (QofSetterFunc)gncOrderSetDateClosed },
-        { ORDER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetNotes, (QofSetterFunc)gncOrderSetNotes },
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderGetActive, (QofSetterFunc)gncOrderSetActive },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params);
-
-    return qof_object_register (&gncOrderDesc);
-}
-
-gint64 gncOrderNextID (QofBook *book)
-{
-    return qof_book_get_counter (book, _GNC_MOD_NAME);
-}

Deleted: gnucash/trunk/src/business/business-core/gncOrder.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOrder.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,124 +0,0 @@
-/********************************************************************\
- * gncOrder.h -- the Core Business Order Interface                  *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/* NOTE: Removed from doxygen by warlord on 2004-05-07 because
- * this module is not fully implemented at this time.
- */
-/* @addtogroup Business
-    @{ */
-/* @addtogroup Order
-    @{ */
-/* @file gncOrder.h
-    @brief Business Order Interface
-    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_ORDER_H_
-#define GNC_ORDER_H_
-
-typedef struct _gncOrder GncOrder;
-typedef struct _gncOrderClass GncOrderClass;
-
-#include "gncEntry.h"
-#include "gncOwner.h"
-#include "qof.h"
-
-#define GNC_ID_ORDER "gncOrder"
-
-/* --- type macros --- */
-#define GNC_TYPE_ORDER            (gnc_order_get_type ())
-#define GNC_ORDER(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ORDER, GncOrder))
-#define GNC_ORDER_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ORDER, GncOrderClass))
-#define GNC_IS_ORDER(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ORDER))
-#define GNC_IS_ORDER_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ORDER))
-#define GNC_ORDER_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ORDER, GncOrderClass))
-GType gnc_order_get_type(void);
-
-/* Create/Destroy Functions */
-
-GncOrder *gncOrderCreate (QofBook *book);
-void gncOrderDestroy (GncOrder *order);
-
-/* Set Functions */
-
-void gncOrderSetID (GncOrder *order, const char *id);
-void gncOrderSetOwner (GncOrder *order, GncOwner *owner);
-void gncOrderSetDateOpened (GncOrder *order, Timespec date);
-void gncOrderSetDateClosed (GncOrder *order, Timespec date);
-void gncOrderSetNotes (GncOrder *order, const char *notes);
-void gncOrderSetReference (GncOrder *order, const char *reference);
-void gncOrderSetActive (GncOrder *order, gboolean active);
-
-/* Add an Entry to the Order */
-void gncOrderAddEntry (GncOrder *order, GncEntry *entry);
-void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry);
-
-/* Get Functions */
-
-const char * gncOrderGetID (const GncOrder *order);
-GncOwner * gncOrderGetOwner (GncOrder *order);
-Timespec gncOrderGetDateOpened (const GncOrder *order);
-Timespec gncOrderGetDateClosed (const GncOrder *order);
-const char * gncOrderGetNotes (const GncOrder *order);
-const char * gncOrderGetReference (const GncOrder *order);
-gboolean gncOrderGetActive (const GncOrder *order);
-
-/* Get the list Entries */
-GList * gncOrderGetEntries (GncOrder *order);
-
-void gncOrderBeginEdit (GncOrder *order);
-void gncOrderCommitEdit (GncOrder *order);
-int gncOrderCompare (const GncOrder *a, const GncOrder *b);
-gboolean gncOrderEqual(const GncOrder *a, const GncOrder *b);
-
-gboolean gncOrderIsClosed (const GncOrder *order);
-
-/** Return a pointer to the instance gncOrder that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncOrder * gncOrderLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncOrder * gncOrderLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ORDER, GncOrder);
-}
-
-#define ORDER_ID	"id"
-#define ORDER_REFERENCE	"reference"
-#define ORDER_OWNER	"owner"
-#define ORDER_OPENED	"date_opened"
-#define ORDER_CLOSED	"date_closed"
-#define ORDER_IS_CLOSED	"is_closed?"
-#define ORDER_NOTES	"notes"
-
-/** deprecated functions */
-#define gncOrderGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-#define gncOrderGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
-
-#endif /* GNC_ORDER_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncOrderP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrderP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOrderP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,59 +0,0 @@
-/********************************************************************\
- * gncOrderP.h -- the Core Busines Order Interface                  *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_ORDERP_H_
-#define GNC_ORDERP_H_
-
-#include "gncOrder.h"
-
-gboolean gncOrderRegister (void);
-gint64 gncOrderNextID (QofBook *book);
-
-/** The gncCloneOrder() routine makes a copy of the indicated
- *  order, placing it in the indicated book.  It copies
- *  the id, notes, reference, etc.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncOrder * gncCloneOrder (GncOrder *from, QofBook *);
-
-/** The gncOrderObtainTwin() will find the 'twin' of the
- *  indicated order in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneOrder()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncOrder * gncOrderObtainTwin (GncOrder *from, QofBook *book);
-
-#define gncOrderSetGUID(O,G) qof_instance_set_guid(QOF_INSTANCE(O),(G))
-
-#endif /* GNC_ORDERP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncOwner.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOwner.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,586 +0,0 @@
-/********************************************************************\
- * gncOwner.c -- Business Interface:  Object OWNERs                 *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001, 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
- * Copyright (c) 2006 David Hampton <hampton at employees.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>		/* for memcpy() */
-
-#include "gncCustomerP.h"
-#include "gncEmployeeP.h"
-#include "gncJobP.h"
-#include "gncOwner.h"
-#include "gncOwnerP.h"
-#include "gncVendorP.h"
-
-#define _GNC_MOD_NAME	GNC_ID_OWNER
-
-#define GNC_OWNER_ID	"gncOwner"
-#define GNC_OWNER_TYPE	"owner-type"
-#define GNC_OWNER_GUID	"owner-guid"
-
-GncOwner * gncOwnerCreate (void)
-{
-    GncOwner *o;
-
-    o = g_new0 (GncOwner, 1);
-    o->type = GNC_OWNER_NONE;
-    return o;
-}
-
-void gncOwnerDestroy (GncOwner *owner)
-{
-    if (!owner) return;
-    g_free (owner);
-}
-
-void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
-{
-    if (!owner) return;
-    owner->type = GNC_OWNER_UNDEFINED;
-    owner->owner.undefined = obj;
-}
-
-void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
-{
-    if (!owner) return;
-    owner->type = GNC_OWNER_CUSTOMER;
-    owner->owner.customer = customer;
-}
-
-void gncOwnerInitJob (GncOwner *owner, GncJob *job)
-{
-    if (!owner) return;
-    owner->type = GNC_OWNER_JOB;
-    owner->owner.job = job;
-}
-
-void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
-{
-    if (!owner) return;
-    owner->type = GNC_OWNER_VENDOR;
-    owner->owner.vendor = vendor;
-}
-
-void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee)
-{
-    if (!owner) return;
-    owner->type = GNC_OWNER_EMPLOYEE;
-    owner->owner.employee = employee;
-}
-
-GncOwnerType gncOwnerGetType (const GncOwner *owner)
-{
-    if (!owner) return GNC_OWNER_NONE;
-    return owner->type;
-}
-
-QofIdType
-qofOwnerGetType(const GncOwner *owner)
-{
-    QofIdType type;
-
-    type = NULL;
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE :
-    {
-        type = NULL;
-        break;
-    }
-    case GNC_OWNER_UNDEFINED :
-    {
-        type = NULL;
-        break;
-    }
-    case GNC_OWNER_CUSTOMER :
-    {
-        type = GNC_ID_CUSTOMER;
-        break;
-    }
-    case GNC_OWNER_JOB :
-    {
-        type = GNC_ID_JOB;
-        break;
-    }
-    case GNC_OWNER_VENDOR :
-    {
-        type = GNC_ID_VENDOR;
-        break;
-    }
-    case GNC_OWNER_EMPLOYEE :
-    {
-        type = GNC_ID_EMPLOYEE;
-        break;
-    }
-    }
-    return type;
-}
-
-QofInstance*
-qofOwnerGetOwner (const GncOwner *owner)
-{
-    QofInstance *ent;
-
-    if (!owner)
-    {
-        return NULL;
-    }
-    ent = NULL;
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE :
-    {
-        break;
-    }
-    case GNC_OWNER_UNDEFINED :
-    {
-        break;
-    }
-    case GNC_OWNER_CUSTOMER :
-    {
-        ent = QOF_INSTANCE(owner->owner.customer);
-        break;
-    }
-    case GNC_OWNER_JOB :
-    {
-        ent = QOF_INSTANCE(owner->owner.job);
-        break;
-    }
-    case GNC_OWNER_VENDOR :
-    {
-        ent = QOF_INSTANCE(owner->owner.vendor);
-        break;
-    }
-    case GNC_OWNER_EMPLOYEE :
-    {
-        ent = QOF_INSTANCE(owner->owner.employee);
-        break;
-    }
-    }
-    return ent;
-}
-
-void
-qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
-{
-    if (!owner || !ent)
-    {
-        return;
-    }
-    if (0 == safe_strcmp(ent->e_type, GNC_ID_CUSTOMER))
-    {
-        owner->type = GNC_OWNER_CUSTOMER;
-        gncOwnerInitCustomer(owner, (GncCustomer*)ent);
-    }
-    if (0 == safe_strcmp(ent->e_type, GNC_ID_JOB))
-    {
-        owner->type = GNC_OWNER_JOB;
-        gncOwnerInitJob(owner, (GncJob*)ent);
-    }
-    if (0 == safe_strcmp(ent->e_type, GNC_ID_VENDOR))
-    {
-        owner->type = GNC_OWNER_VENDOR;
-        gncOwnerInitVendor(owner, (GncVendor*)ent);
-    }
-    if (0 == safe_strcmp(ent->e_type, GNC_ID_EMPLOYEE))
-    {
-        owner->type = GNC_OWNER_EMPLOYEE;
-        gncOwnerInitEmployee(owner, (GncEmployee*)ent);
-    }
-}
-
-gpointer gncOwnerGetUndefined (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    if (owner->type != GNC_OWNER_UNDEFINED) return NULL;
-    return owner->owner.undefined;
-}
-
-GncCustomer * gncOwnerGetCustomer (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    if (owner->type != GNC_OWNER_CUSTOMER) return NULL;
-    return owner->owner.customer;
-}
-
-GncJob * gncOwnerGetJob (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    if (owner->type != GNC_OWNER_JOB) return NULL;
-    return owner->owner.job;
-}
-
-GncVendor * gncOwnerGetVendor (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    if (owner->type != GNC_OWNER_VENDOR) return NULL;
-    return owner->owner.vendor;
-}
-
-GncEmployee * gncOwnerGetEmployee (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    if (owner->type != GNC_OWNER_EMPLOYEE) return NULL;
-    return owner->owner.employee;
-}
-
-gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE:
-    case GNC_OWNER_UNDEFINED:
-    default:
-        return NULL;
-    case GNC_OWNER_CUSTOMER:
-        return gncCustomerGetCurrency (owner->owner.customer);
-    case GNC_OWNER_VENDOR:
-        return gncVendorGetCurrency (owner->owner.vendor);
-    case GNC_OWNER_EMPLOYEE:
-        return gncEmployeeGetCurrency (owner->owner.employee);
-    case GNC_OWNER_JOB:
-        return gncOwnerGetCurrency (gncJobGetOwner (owner->owner.job));
-    }
-}
-
-void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
-{
-    if (!src || !dest) return;
-    if (src == dest) return;
-    memcpy (dest, src, sizeof (*dest));
-}
-
-GncOwner
-gncCloneOwner (const GncOwner *from, QofBook *book)
-{
-    GncOwner owner = { GNC_OWNER_NONE };
-    if (!from) return owner;
-    owner.type = from->type;
-    switch (from->type)
-    {
-    case GNC_OWNER_NONE:
-        return owner;
-    case GNC_OWNER_UNDEFINED:
-        owner.owner.undefined = from->owner.undefined;  /* XXX probably wrong ! */
-        return owner;
-    case GNC_OWNER_CUSTOMER:
-        owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book);
-        return owner;
-    case GNC_OWNER_JOB:
-        owner.owner.job = gncJobObtainTwin (from->owner.job, book);
-        return owner;
-    case GNC_OWNER_VENDOR:
-        owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book);
-        return owner;
-    case GNC_OWNER_EMPLOYEE:
-        owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book);
-        return owner;
-    default:
-        return owner;
-    }
-}
-
-gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
-{
-    if (!a || !b) return FALSE;
-    if (gncOwnerGetType (a) != gncOwnerGetType (b)) return FALSE;
-    return (a->owner.undefined == b->owner.undefined);
-}
-
-const char * gncOwnerGetName (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE:
-    case GNC_OWNER_UNDEFINED:
-    default:
-        return NULL;
-    case GNC_OWNER_CUSTOMER:
-        return gncCustomerGetName (owner->owner.customer);
-    case GNC_OWNER_JOB:
-        return gncJobGetName (owner->owner.job);
-    case GNC_OWNER_VENDOR:
-        return gncVendorGetName (owner->owner.vendor);
-    case GNC_OWNER_EMPLOYEE:
-        return gncAddressGetName(gncEmployeeGetAddr (owner->owner.employee));
-    }
-}
-
-const GncGUID * gncOwnerGetGUID (const GncOwner *owner)
-{
-    if (!owner) return NULL;
-
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE:
-    case GNC_OWNER_UNDEFINED:
-    default:
-        return NULL;
-    case GNC_OWNER_CUSTOMER:
-        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer));
-    case GNC_OWNER_JOB:
-        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job));
-    case GNC_OWNER_VENDOR:
-        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor));
-    case GNC_OWNER_EMPLOYEE:
-        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee));
-    }
-}
-
-GncGUID gncOwnerRetGUID (GncOwner *owner)
-{
-    const GncGUID *guid = gncOwnerGetGUID (owner);
-    if (guid)
-        return *guid;
-    return *guid_null ();
-}
-
-GncOwner * gncOwnerGetEndOwner (GncOwner *owner)
-{
-    if (!owner) return NULL;
-    switch (owner->type)
-    {
-    case GNC_OWNER_NONE:
-    case GNC_OWNER_UNDEFINED:
-    default:
-        return NULL;
-    case GNC_OWNER_CUSTOMER:
-    case GNC_OWNER_VENDOR:
-    case GNC_OWNER_EMPLOYEE:
-        return owner;
-    case GNC_OWNER_JOB:
-        return gncJobGetOwner (owner->owner.job);
-    }
-}
-
-int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    if (a->type != b->type)
-        return (a->type - b->type);
-
-    switch (a->type)
-    {
-    case GNC_OWNER_NONE:
-    case GNC_OWNER_UNDEFINED:
-    default:
-        return 0;
-    case GNC_OWNER_CUSTOMER:
-        return gncCustomerCompare (a->owner.customer, b->owner.customer);
-    case GNC_OWNER_VENDOR:
-        return gncVendorCompare (a->owner.vendor, b->owner.vendor);
-    case GNC_OWNER_EMPLOYEE:
-        return gncEmployeeCompare (a->owner.employee, b->owner.employee);
-    case GNC_OWNER_JOB:
-        return gncJobCompare (a->owner.job, b->owner.job);
-    }
-}
-
-const GncGUID * gncOwnerGetEndGUID (GncOwner *owner)
-{
-    if (!owner) return NULL;
-    owner = gncOwnerGetEndOwner (owner);
-    return gncOwnerGetGUID (owner);
-}
-
-void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-
-    if (!owner || !lot)
-        return;
-
-    kvp = gnc_lot_get_slots (lot);
-
-    value = kvp_value_new_gint64 (gncOwnerGetType (owner));
-    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
-    kvp_value_delete (value);
-
-    value = kvp_value_new_guid (gncOwnerGetGUID (owner));
-    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
-    kvp_value_delete (value);
-
-}
-
-gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
-{
-    KvpFrame *kvp;
-    KvpValue *value;
-    GncGUID *guid;
-    QofBook *book;
-    GncOwnerType type;
-
-    if (!lot || !owner) return FALSE;
-
-    book = gnc_lot_get_book (lot);
-    kvp = gnc_lot_get_slots (lot);
-
-    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
-    if (!value) return FALSE;
-
-    type = kvp_value_get_gint64 (value);
-
-    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
-    if (!value) return FALSE;
-
-    guid = kvp_value_get_guid (value);
-    if (!guid)
-        return FALSE;
-
-    switch (type)
-    {
-    case GNC_OWNER_CUSTOMER:
-        gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
-        break;
-    case GNC_OWNER_VENDOR:
-        gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
-        break;
-    case GNC_OWNER_EMPLOYEE:
-        gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
-        break;
-    case GNC_OWNER_JOB:
-        gncOwnerInitJob (owner, gncJobLookup (book, guid));
-        break;
-    default:
-        return FALSE;
-    }
-
-    return (owner->owner.undefined != NULL);
-}
-
-gboolean gncOwnerIsValid (const GncOwner *owner)
-{
-    if (!owner) return FALSE;
-    return (owner->owner.undefined != NULL);
-}
-
-KvpFrame* gncOwnerGetSlots(GncOwner* owner)
-{
-    if (!owner) return NULL;
-
-    switch (gncOwnerGetType(owner))
-    {
-    case GNC_OWNER_CUSTOMER:
-    case GNC_OWNER_VENDOR:
-    case GNC_OWNER_EMPLOYEE:
-        return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined));
-    case GNC_OWNER_JOB:
-        return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner)));
-    default:
-        return NULL;
-    }
-}
-
-/* XXX: Yea, this is broken, but it should work fine for Queries.
- * We're single-threaded, right?
- */
-static GncOwner *
-owner_from_lot (GNCLot *lot)
-{
-    static GncOwner owner;
-
-    if (!lot) return NULL;
-    if (gncOwnerGetOwnerFromLot (lot, &owner))
-        return &owner;
-
-    return NULL;
-}
-
-static void
-reg_lot (void)
-{
-    static QofParam params[] =
-    {
-        { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL },
-        { NULL },
-    };
-
-    qof_class_register (GNC_ID_LOT, NULL, params);
-}
-
-gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid)
-{
-    if (!book || !owner || !type || !guid) return FALSE;
-
-    if (0 == safe_strcmp(type, GNC_ID_CUSTOMER))
-    {
-        GncCustomer *customer = gncCustomerLookup(book, guid);
-        gncOwnerInitCustomer(owner, customer);
-        return (NULL != customer);
-    }
-    else if (0 == safe_strcmp(type, GNC_ID_JOB))
-    {
-        GncJob *job = gncJobLookup(book, guid);
-        gncOwnerInitJob(owner, job);
-        return (NULL != job);
-    }
-    else if (0 == safe_strcmp(type, GNC_ID_VENDOR))
-    {
-        GncVendor *vendor = gncVendorLookup(book, guid);
-        gncOwnerInitVendor(owner, vendor);
-        return (NULL != vendor);
-    }
-    else if (0 == safe_strcmp(type, GNC_ID_EMPLOYEE))
-    {
-        GncEmployee *employee = gncEmployeeLookup(book, guid);
-        gncOwnerInitEmployee(owner, employee);
-        return (NULL != employee);
-    }
-    return 0;
-}
-
-gboolean gncOwnerRegister (void)
-{
-    static QofParam params[] =
-    {
-        { OWNER_TYPE, QOF_TYPE_INT64,      (QofAccessFunc)gncOwnerGetType,          NULL },
-        { OWNER_CUSTOMER, GNC_ID_CUSTOMER, (QofAccessFunc)gncOwnerGetCustomer,      NULL },
-        { OWNER_JOB, GNC_ID_JOB,           (QofAccessFunc)gncOwnerGetJob,           NULL },
-        { OWNER_VENDOR, GNC_ID_VENDOR,     (QofAccessFunc)gncOwnerGetVendor,        NULL },
-        { OWNER_EMPLOYEE, GNC_ID_EMPLOYEE, (QofAccessFunc)gncOwnerGetEmployee,      NULL },
-        { OWNER_PARENT, GNC_ID_OWNER,      (QofAccessFunc)gncOwnerGetEndOwner,      NULL },
-        { OWNER_PARENTG, QOF_TYPE_GUID,    (QofAccessFunc)gncOwnerGetEndGUID,       NULL },
-        { OWNER_NAME, QOF_TYPE_STRING,     (QofAccessFunc)gncOwnerGetName, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID,   (QofAccessFunc)gncOwnerGetGUID, NULL },
-        { NULL },
-    };
-
-    qof_class_register (GNC_ID_OWNER, (QofSortFunc)gncOwnerCompare, params);
-    reg_lot ();
-
-    return TRUE;
-}

Deleted: gnucash/trunk/src/business/business-core/gncOwner.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOwner.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,169 +0,0 @@
-/********************************************************************\
- * gncOwner.h -- Business Interface:  Object OWNERs                 *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Owner
-    @{ */
-/** @file gncOwner.h
-    @brief Business Interface:  Object OWNERs
-    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
-    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
-    @author Copyright (c) 2006 David Hampton <hampton at employees.org>
-*/
-
-#ifndef GNC_OWNER_H_
-#define GNC_OWNER_H_
-
-typedef struct _gncOwner GncOwner;
-
-#define GNC_ID_OWNER   "gncOwner"
-
-#include "qof.h"
-#include "gncCustomer.h"
-#include "gncJob.h"
-#include "gncVendor.h"
-#include "gncEmployee.h"
-#include "gnc-lot.h"
-
-typedef enum
-{
-    GNC_OWNER_NONE ,
-    GNC_OWNER_UNDEFINED ,
-    GNC_OWNER_CUSTOMER ,
-    GNC_OWNER_JOB ,
-    GNC_OWNER_VENDOR ,
-    GNC_OWNER_EMPLOYEE ,
-} GncOwnerType;
-
-/** \name QOF handling
-
-Whilst GncOwner is not a formal QOF object, these functions
-are still expected to be useful in making GncOwner transparent
-to QOF as they can be used by objects like GncInvoice.
-@{
-*/
-/** return the type for the collection. */
-QofIdType qofOwnerGetType(const GncOwner *owner);
-/** return the owner itself as an entity. */
-QofInstance* qofOwnerGetOwner (const GncOwner *owner);
-/** set the owner from the entity. */
-void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
-
-gboolean
-gncOwnerRegister(void);
-
-/** @} */
-
-#ifndef SWIG
-
-/** \struct GncOwner */
-struct _gncOwner
-{
-    GncOwnerType     type;      /**< Customer, Job, Vendor, Employee or Undefined. */
-    union
-    {
-        gpointer       undefined;
-        GncCustomer *  customer;
-        GncJob *       job;
-        GncVendor *    vendor;
-        GncEmployee *  employee;
-    } owner;                   /**< holds the pointer to the owner object. */
-    gpointer         qof_temp; /**< Set type independently of the owner. */
-};
-
-#endif /* SWIG */
-
-/** \name Setup routines
-@{
-*/
-void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
-void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
-void gncOwnerInitJob (GncOwner *owner, GncJob *job);
-void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
-void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee);
-/** @} */
-/** \name Get routines.
-@{
-*/
-GncOwnerType gncOwnerGetType (const GncOwner *owner);
-gpointer gncOwnerGetUndefined (const GncOwner *owner);
-GncCustomer * gncOwnerGetCustomer (const GncOwner *owner);
-GncJob * gncOwnerGetJob (const GncOwner *owner);
-GncVendor * gncOwnerGetVendor (const GncOwner *owner);
-GncEmployee * gncOwnerGetEmployee (const GncOwner *owner);
-/** @} */
-void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
-gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
-int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
-
-const char * gncOwnerGetName (const GncOwner *owner);
-gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
-
-/** Get the GncGUID of the immediate owner */
-const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
-GncGUID gncOwnerRetGUID (GncOwner *owner);
-
-gboolean gncOwnerIsValid (const GncOwner *owner);
-
-/**
- * Get the "parent" Owner or GncGUID thereof.  The "parent" owner
- * is the Customer or Vendor, or the Owner of a Job
- */
-GncOwner * gncOwnerGetEndOwner (GncOwner *owner);
-const GncGUID * gncOwnerGetEndGUID (GncOwner *owner);
-
-/** attach an owner to a lot */
-void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
-
-/** Get the owner from the lot.  If an owner is found in the lot,
- * fill in "owner" and return TRUE.  Otherwise return FALSE.
- */
-gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
-
-gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
-
-/** Get the kvp-frame from the underlying owner object */
-KvpFrame* gncOwnerGetSlots(GncOwner* owner);
-
-#define OWNER_TYPE        "type"
-#define OWNER_TYPE_STRING "type-string"  /**< Allows the type to be handled externally. */
-#define OWNER_CUSTOMER    "customer"
-#define OWNER_JOB         "job"
-#define OWNER_VENDOR      "vendor"
-#define OWNER_EMPLOYEE    "employee"
-#define OWNER_PARENT      "parent"
-#define OWNER_PARENTG     "parent-guid"
-#define OWNER_NAME        "name"
-
-#define OWNER_FROM_LOT    "owner-from-lot"
-
-/**
- * These two functions are mainly for the convenience of scheme code.
- * Normal C code has no need to ever use these two functions, and rather
- * can just use a GncOwner directly and just pass around a pointer to it.
- */
-GncOwner * gncOwnerCreate (void);
-void gncOwnerDestroy (GncOwner *owner);
-
-#endif /* GNC_OWNER_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncOwnerP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwnerP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncOwnerP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,40 +0,0 @@
-/********************************************************************\
- * gncOwnerP.h -- Business Interface:  Object OWNERs private file   *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001, 2002 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_OWNERP_H_
-#define GNC_OWNERP_H_
-
-#include "gncOwner.h"
-
-gboolean gncOwnerRegister (void);
-
-/** The gncCloneOwner() routine makes a copy of the indicated
- *  owner union structure.
- */
-GncOwner gncCloneOwner (const GncOwner *from, QofBook *);
-
-#endif /* GNC_OWNERP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncTaxTable.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,1075 +0,0 @@
-/********************************************************************\
- * gncTaxTable.c -- the Gnucash Tax Table interface                 *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-
-#include "gncTaxTableP.h"
-
-struct _gncTaxTable
-{
-    QofInstance     inst;
-    char *          name;
-    GncTaxTableEntryList*  entries;
-    Timespec        modtime;      /* internal date of last modtime */
-
-    /* See src/doc/business.txt for an explanation of the following */
-    /* Code that handles this is *identical* to that in gncBillTerm */
-    gint64          refcount;
-    GncTaxTable *   parent;       /* if non-null, we are an immutable child */
-    GncTaxTable *   child;        /* if non-null, we have not changed */
-    gboolean        invisible;
-    GList *         children;     /* list of children for disconnection */
-};
-
-struct _gncTaxTableClass
-{
-    QofInstanceClass parent_class;
-};
-
-struct _gncTaxTableEntry
-{
-    GncTaxTable *   table;
-    Account *       account;
-    GncAmountType   type;
-    gnc_numeric     amount;
-};
-
-struct _book_info
-{
-    GList *         tables;          /* visible tables */
-};
-
-static GncTaxTableEntry * CloneTaxEntry (const GncTaxTableEntry*, QofBook *);
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-/* =============================================================== */
-/* You must edit the functions in this block in tandem.  KEEP THEM IN
-   SYNC! */
-
-#define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);
-const char *
-gncAmountTypeToString (GncAmountType type)
-{
-    switch (type)
-    {
-        GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_VALUE, "VALUE");
-        GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_PERCENT, "PERCENT");
-    default:
-        g_warning ("asked to translate unknown amount type %d.\n", type);
-        break;
-    }
-    return(NULL);
-}
-
-const char *
-gncTaxIncludedTypeToString (GncTaxIncluded type)
-{
-    switch (type)
-    {
-        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_YES, "YES");
-        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_NO, "NO");
-        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_USEGLOBAL, "USEGLOBAL");
-    default:
-        g_warning ("asked to translate unknown taxincluded type %d.\n", type);
-        break;
-    }
-    return(NULL);
-}
-#undef GNC_RETURN_ENUM_AS_STRING
-#define GNC_RETURN_ON_MATCH(s,x) \
-  if(safe_strcmp((s), (str)) == 0) { *type = x; return(TRUE); }
-gboolean
-gncAmountStringToType (const char *str, GncAmountType *type)
-{
-    GNC_RETURN_ON_MATCH ("VALUE", GNC_AMT_TYPE_VALUE);
-    GNC_RETURN_ON_MATCH ("PERCENT", GNC_AMT_TYPE_PERCENT);
-    g_warning ("asked to translate unknown amount type string %s.\n",
-               str ? str : "(null)");
-
-    return(FALSE);
-}
-
-gboolean
-gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type)
-{
-    GNC_RETURN_ON_MATCH ("YES", GNC_TAXINCLUDED_YES);
-    GNC_RETURN_ON_MATCH ("NO", GNC_TAXINCLUDED_NO);
-    GNC_RETURN_ON_MATCH ("USEGLOBAL", GNC_TAXINCLUDED_USEGLOBAL);
-    g_warning ("asked to translate unknown taxincluded type string %s.\n",
-               str ? str : "(null)");
-
-    return(FALSE);
-}
-#undef GNC_RETURN_ON_MATCH
-
-/* =============================================================== */
-/* Misc inline functions */
-
-#define _GNC_MOD_NAME        GNC_ID_TAXTABLE
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncTaxTableBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-static inline void
-mark_table (GncTaxTable *table)
-{
-    qof_instance_set_dirty(&table->inst);
-    qof_event_gen (&table->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-static inline void
-maybe_resort_list (GncTaxTable *table)
-{
-    struct _book_info *bi;
-
-    if (table->parent || table->invisible) return;
-    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
-    bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare);
-}
-
-static inline void
-mod_table (GncTaxTable *table)
-{
-    timespecFromTime_t (&table->modtime, time(NULL));
-}
-
-static inline void addObj (GncTaxTable *table)
-{
-    struct _book_info *bi;
-    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
-    bi->tables = g_list_insert_sorted (bi->tables, table,
-                                       (GCompareFunc)gncTaxTableCompare);
-}
-
-static inline void remObj (GncTaxTable *table)
-{
-    struct _book_info *bi;
-    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
-    bi->tables = g_list_remove (bi->tables, table);
-}
-
-static inline void
-gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
-{
-    g_return_if_fail(table);
-    g_return_if_fail(child);
-    g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
-
-    table->children = g_list_prepend(table->children, child);
-}
-
-static inline void
-gncTaxTableRemoveChild (GncTaxTable *table, const GncTaxTable *child)
-{
-    g_return_if_fail(table);
-    g_return_if_fail(child);
-
-    if (qof_instance_get_destroying(table)) return;
-
-    table->children = g_list_remove(table->children, child);
-}
-
-/* =============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncTaxTable, gnc_taxtable, QOF_TYPE_INSTANCE);
-
-static void
-gnc_taxtable_init(GncTaxTable* tt)
-{
-}
-
-static void
-gnc_taxtable_dispose(GObject *ttp)
-{
-    G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
-}
-
-static void
-gnc_taxtable_finalize(GObject* ttp)
-{
-    G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
-}
-
-static void
-gnc_taxtable_get_property (GObject         *object,
-                           guint            prop_id,
-                           GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncTaxTable *tt;
-
-    g_return_if_fail(GNC_IS_TAXTABLE(object));
-
-    tt = GNC_TAXTABLE(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, tt->name);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_taxtable_set_property (GObject         *object,
-                           guint            prop_id,
-                           const GValue          *value,
-                           GParamSpec      *pspec)
-{
-    GncTaxTable *tt;
-
-    g_return_if_fail(GNC_IS_TAXTABLE(object));
-
-    tt = GNC_TAXTABLE(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncTaxTableSetName(tt, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Return displayable name */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncTaxTable* tt;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
-
-    tt = GNC_TAXTABLE(inst);
-    return g_strdup_printf("Tax table %s", tt->name);
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncTaxTable* tt;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
-
-    tt = GNC_TAXTABLE(inst);
-
-    if (GNC_IS_ACCOUNT(ref))
-    {
-        GList* node;
-
-        for (node = tt->entries; node != NULL; node = node->next)
-        {
-            GncTaxTableEntry* tte = node->data;
-
-            if (tte->account == GNC_ACCOUNT(ref))
-            {
-                return TRUE;
-            }
-        }
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_ACCOUNT(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_taxtable_class_init (GncTaxTableClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_taxtable_dispose;
-    gobject_class->finalize = gnc_taxtable_finalize;
-    gobject_class->set_property = gnc_taxtable_set_property;
-    gobject_class->get_property = gnc_taxtable_get_property;
-
-    qof_class->get_display_name = impl_get_display_name;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "TaxTable Name",
-                          "The accountName is an arbitrary string "
-                          "assigned by the user.  It is intended to "
-                          "a short, 10 to 30 character long string "
-                          "that is displayed by the GUI as the "
-                          "tax table mnemonic.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncTaxTable *
-gncTaxTableCreate (QofBook *book)
-{
-    GncTaxTable *table;
-    if (!book) return NULL;
-
-    table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
-    qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
-    table->name = CACHE_INSERT ("");
-    addObj (table);
-    qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
-    return table;
-}
-
-
-GncTaxTable *
-gncCloneTaxTable (GncTaxTable *from, QofBook *book)
-{
-    GList *node;
-    GncTaxTable *table;
-    if (!book) return NULL;
-
-    table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
-    qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&table->inst, &from->inst);
-
-    table->name = CACHE_INSERT (from->name);
-    table->modtime = from->modtime;
-    table->invisible = from->invisible;
-
-    table->refcount = 0;
-
-    /* Make copies of parents and children. Note that this can be
-     * a recursive copy ... treat as doubly-linked list. */
-    if (from->child)
-    {
-        table->child = gncTaxTableObtainTwin (from->child, book);
-        table->child->parent = table;
-    }
-    if (from->parent)
-    {
-        table->parent = gncTaxTableObtainTwin (from->parent, book);
-        table->parent->child = table;
-    }
-    for (node = g_list_last(from->children); node; node = node->next)
-    {
-        GncTaxTable *tbl = node->data;
-        tbl = gncTaxTableObtainTwin (tbl, book);
-        tbl->parent = table;
-        table->children = g_list_prepend(table->children, tbl);
-    }
-
-    /* Copy tax entries, preserving the order in the list */
-    table->entries = NULL;
-    for (node = g_list_last(from->entries); node; node = node->prev)
-    {
-        GncTaxTableEntry *ent = node->data;
-        ent = CloneTaxEntry (ent, book);
-        table->entries = g_list_prepend (table->entries, ent);
-    }
-
-    addObj (table);
-    qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
-    return table;
-}
-
-GncTaxTable *
-gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book)
-{
-    GncTaxTable *table;
-    if (!from) return NULL;
-
-    table = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!table)
-    {
-        table = gncCloneTaxTable (table, book);
-    }
-    return table;
-}
-
-
-void
-gncTaxTableDestroy (GncTaxTable *table)
-{
-    if (!table) return;
-    qof_instance_set_destroying(table, TRUE);
-    qof_instance_set_dirty (&table->inst);
-    gncTaxTableCommitEdit (table);
-}
-
-static void
-gncTaxTableFree (GncTaxTable *table)
-{
-    GList *list;
-    GncTaxTable *child;
-
-    if (!table) return;
-
-    qof_event_gen (&table->inst, QOF_EVENT_DESTROY, NULL);
-    CACHE_REMOVE (table->name);
-    remObj (table);
-
-    /* destroy the list of entries */
-    for (list = table->entries; list; list = list->next)
-        gncTaxTableEntryDestroy (list->data);
-    g_list_free (table->entries);
-
-    if (!qof_instance_get_destroying(table))
-        PERR("free a taxtable without do_free set!");
-
-    /* disconnect from parent */
-    if (table->parent)
-        gncTaxTableRemoveChild(table->parent, table);
-
-    /* disconnect from the children */
-    for (list = table->children; list; list = list->next)
-    {
-        child = list->data;
-        gncTaxTableSetParent(child, NULL);
-    }
-    g_list_free(table->children);
-
-    /* qof_instance_release (&table->inst); */
-    g_object_unref (table);
-}
-
-/* =============================================================== */
-
-GncTaxTableEntry * gncTaxTableEntryCreate (void)
-{
-    GncTaxTableEntry *entry;
-    entry = g_new0 (GncTaxTableEntry, 1);
-    entry->amount = gnc_numeric_zero ();
-    return entry;
-}
-
-void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
-{
-    if (!entry) return;
-    g_free (entry);
-}
-
-/** Makes a clone. The account is from the appriate book.
- *  Note that the table is left blank (for performance reasons
- *  we set it above, when cloning the table).
- */
-static GncTaxTableEntry *
-CloneTaxEntry (const GncTaxTableEntry*from, QofBook *book)
-{
-    QofInstance *acc;
-    GncTaxTableEntry *entry;
-    entry = g_new0 (GncTaxTableEntry, 1);
-
-    entry->type = from->type;
-    entry->amount = from->amount;
-
-    acc = qof_instance_lookup_twin (QOF_INSTANCE(from->account), book);
-    entry->account = (Account *) acc;
-    return entry;
-}
-
-/* =============================================================== */
-/* Set Functions */
-
-void gncTaxTableSetName (GncTaxTable *table, const char *name)
-{
-    if (!table || !name) return;
-    SET_STR (table, table->name, name);
-    mark_table (table);
-    maybe_resort_list (table);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent)
-{
-    if (!table) return;
-    gncTaxTableBeginEdit (table);
-    if (table->parent)
-        gncTaxTableRemoveChild(table->parent, table);
-    table->parent = parent;
-    if (parent)
-        gncTaxTableAddChild(parent, table);
-    table->refcount = 0;
-    gncTaxTableMakeInvisible (table);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child)
-{
-    if (!table) return;
-    gncTaxTableBeginEdit (table);
-    table->child = child;
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableIncRef (GncTaxTable *table)
-{
-    if (!table) return;
-    if (table->parent || table->invisible) return;        /* children dont need refcounts */
-    gncTaxTableBeginEdit (table);
-    table->refcount++;
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableDecRef (GncTaxTable *table)
-{
-    if (!table) return;
-    if (table->parent || table->invisible) return;        /* children dont need refcounts */
-    gncTaxTableBeginEdit (table);
-    table->refcount--;
-    g_return_if_fail (table->refcount >= 0);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount)
-{
-    if (!table) return;
-    table->refcount = refcount;
-}
-
-void gncTaxTableMakeInvisible (GncTaxTable *table)
-{
-    struct _book_info *bi;
-    if (!table) return;
-    gncTaxTableBeginEdit (table);
-    table->invisible = TRUE;
-    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
-    bi->tables = g_list_remove (bi->tables, table);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account)
-{
-    if (!entry || !account) return;
-    if (entry->account == account) return;
-    entry->account = account;
-    if (entry->table)
-    {
-        mark_table (entry->table);
-        mod_table (entry->table);
-    }
-}
-
-void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type)
-{
-    if (!entry) return;
-    if (entry->type == type) return;
-    entry->type = type;
-    if (entry->table)
-    {
-        mark_table (entry->table);
-        mod_table (entry->table);
-    }
-}
-
-void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount)
-{
-    if (!entry) return;
-    if (gnc_numeric_eq (entry->amount, amount)) return;
-    entry->amount = amount;
-    if (entry->table)
-    {
-        mark_table (entry->table);
-        mod_table (entry->table);
-    }
-}
-
-void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry)
-{
-    if (!table || !entry) return;
-    if (entry->table == table) return; /* already mine */
-
-    gncTaxTableBeginEdit (table);
-    if (entry->table)
-        gncTaxTableRemoveEntry (entry->table, entry);
-
-    entry->table = table;
-    table->entries = g_list_insert_sorted (table->entries, entry,
-                                           (GCompareFunc)gncTaxTableEntryCompare);
-    mark_table (table);
-    mod_table (table);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry)
-{
-    if (!table || !entry) return;
-    gncTaxTableBeginEdit (table);
-    entry->table = NULL;
-    table->entries = g_list_remove (table->entries, entry);
-    mark_table (table);
-    mod_table (table);
-    gncTaxTableCommitEdit (table);
-}
-
-void gncTaxTableChanged (GncTaxTable *table)
-{
-    if (!table) return;
-    gncTaxTableBeginEdit (table);
-    table->child = NULL;
-    gncTaxTableCommitEdit (table);
-}
-
-/* =============================================================== */
-
-void gncTaxTableBeginEdit (GncTaxTable *table)
-{
-    qof_begin_edit(&table->inst);
-}
-
-static void gncTaxTableOnError (QofInstance *inst, QofBackendError errcode)
-{
-    PERR("TaxTable QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncTaxTableOnDone (QofInstance *inst) {}
-
-static void table_free (QofInstance *inst)
-{
-    GncTaxTable *table = (GncTaxTable *) inst;
-    gncTaxTableFree (table);
-}
-
-void gncTaxTableCommitEdit (GncTaxTable *table)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(table))) return;
-    qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,
-                           gncTaxTableOnDone, table_free);
-}
-
-
-/* =============================================================== */
-/* Get Functions */
-
-GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name)
-{
-    GList *list = gncTaxTableGetTables (book);
-
-    for ( ; list; list = list->next)
-    {
-        GncTaxTable *table = list->data;
-        if (!safe_strcmp (table->name, name))
-            return list->data;
-    }
-    return NULL;
-}
-
-GList * gncTaxTableGetTables (QofBook *book)
-{
-    struct _book_info *bi;
-    if (!book) return NULL;
-
-    bi = qof_book_get_data (book, _GNC_MOD_NAME);
-    return bi->tables;
-}
-
-const char *gncTaxTableGetName (const GncTaxTable *table)
-{
-    if (!table) return NULL;
-    return table->name;
-}
-
-static GncTaxTableEntry *gncTaxTableEntryCopy (const GncTaxTableEntry *entry)
-{
-    GncTaxTableEntry *e;
-    if (!entry) return NULL;
-
-    e = gncTaxTableEntryCreate ();
-    gncTaxTableEntrySetAccount (e, entry->account);
-    gncTaxTableEntrySetType (e, entry->type);
-    gncTaxTableEntrySetAmount (e, entry->amount);
-
-    return e;
-}
-
-static GncTaxTable *gncTaxTableCopy (const GncTaxTable *table)
-{
-    GncTaxTable *t;
-    GList *list;
-
-    if (!table) return NULL;
-    t = gncTaxTableCreate (qof_instance_get_book(table));
-    gncTaxTableSetName (t, table->name);
-    for (list = table->entries; list; list = list->next)
-    {
-        GncTaxTableEntry *entry, *e;
-        entry = list->data;
-        e = gncTaxTableEntryCopy (entry);
-        gncTaxTableAddEntry (t, e);
-    }
-    return t;
-}
-
-GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new)
-{
-    GncTaxTable *child = NULL;
-
-    if (!table) return NULL;
-    if (table->child) return table->child;
-    if (table->parent || table->invisible) return table;
-    if (make_new)
-    {
-        child = gncTaxTableCopy (table);
-        gncTaxTableSetChild (table, child);
-        gncTaxTableSetParent (child, table);
-    }
-    return child;
-}
-
-GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table)
-{
-    if (!table) return NULL;
-    return table->parent;
-}
-
-GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table)
-{
-    if (!table) return NULL;
-    return table->entries;
-}
-
-gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
-{
-    if (!table) return 0;
-    return table->refcount;
-}
-
-Timespec gncTaxTableLastModified (const GncTaxTable *table)
-{
-    Timespec ts = { 0 , 0 };
-    if (!table) return ts;
-    return table->modtime;
-}
-
-gboolean gncTaxTableGetInvisible (const GncTaxTable *table)
-{
-    if (!table) return FALSE;
-    return table->invisible;
-}
-
-Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry)
-{
-    if (!entry) return NULL;
-    return entry->account;
-}
-
-GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry)
-{
-    if (!entry) return 0;
-    return entry->type;
-}
-
-gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry)
-{
-    if (!entry) return gnc_numeric_zero();
-    return entry->amount;
-}
-
-GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry )
-{
-    if (!entry) return NULL;
-    return entry->table;
-}
-
-int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
-{
-    char *name_a, *name_b;
-    int retval;
-
-    if (!a && !b) return 0;
-    if (!a) return -1;
-    if (!b) return 1;
-
-    name_a = gnc_account_get_full_name (a->account);
-    name_b = gnc_account_get_full_name (b->account);
-    retval = safe_strcmp(name_a, name_b);
-    g_free(name_a);
-    g_free(name_b);
-
-    if (retval)
-        return retval;
-
-    return gnc_numeric_compare (a->amount, b->amount);
-}
-
-int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b)
-{
-    if (!a && !b) return 0;
-    if (!a) return -1;
-    if (!b) return 1;
-    return safe_strcmp (a->name, b->name);
-}
-
-gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    if (!xaccAccountEqual(a->account, b->account, TRUE))
-    {
-        PWARN("accounts differ");
-        return FALSE;
-    }
-
-    if (a->type != b->type)
-    {
-        PWARN("types differ");
-        return FALSE;
-    }
-
-    if (!gnc_numeric_equal(a->amount, b->amount))
-    {
-        PWARN("amounts differ");
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL || b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
-    g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("Names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-
-    if (a->invisible != b->invisible)
-    {
-        PWARN("invisible flags differ");
-        return FALSE;
-    }
-
-    if ((a->entries != NULL) != (b->entries != NULL))
-    {
-        PWARN("only one has entries");
-        return FALSE;
-    }
-
-    if (a->entries != NULL && b->entries != NULL)
-    {
-        GncTaxTableEntryList* a_node;
-        GncTaxTableEntryList* b_node;
-
-        for (a_node = a->entries, b_node = b->entries;
-                a_node != NULL && b_node != NULL;
-                a_node = a_node->next, b_node = b_node->next)
-        {
-            if (!gncTaxTableEntryEqual((GncTaxTableEntry*)a_node->data,
-                                       (GncTaxTableEntry*)b_node->data))
-            {
-                PWARN("entries differ");
-                return FALSE;
-            }
-        }
-
-        if (a_node != NULL || b_node != NULL)
-        {
-            PWARN("Unequal number of entries");
-            return FALSE;
-        }
-    }
-
-#if 0
-    /* See src/doc/business.txt for an explanation of the following */
-    /* Code that handles this is *identical* to that in gncBillTerm */
-    gint64          refcount;
-    GncTaxTable *   parent;       /* if non-null, we are an immutable child */
-    GncTaxTable *   child;        /* if non-null, we have not changed */
-    GList *         children;     /* list of children for disconnection */
-#endif
-
-    return TRUE;
-}
-
-/*
- * This will add value to the account-value for acc, creating a new
- * list object if necessary
- */
-GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value)
-{
-    GList *li;
-    GncAccountValue *res = NULL;
-
-    g_return_val_if_fail (acc, list);
-    g_return_val_if_fail (gnc_numeric_check (value) == GNC_ERROR_OK, list);
-
-    /* Try to find the account in the list */
-    for (li = list; li; li = li->next)
-    {
-        res = li->data;
-        if (res->account == acc)
-        {
-            res->value = gnc_numeric_add (res->value, value, GNC_DENOM_AUTO,
-                                          GNC_DENOM_LCD);
-            return list;
-        }
-    }
-    /* Nope, didn't find it. */
-
-    res = g_new0 (GncAccountValue, 1);
-    res->account = acc;
-    res->value = value;
-    return g_list_prepend (list, res);
-}
-
-/* Merge l2 into l1.  l2 is not touched. */
-GList *gncAccountValueAddList (GList *l1, GList *l2)
-{
-    GList *li;
-
-    for (li = l2; li; li = li->next )
-    {
-        GncAccountValue *val = li->data;
-        l1 = gncAccountValueAdd (l1, val->account, val->value);
-    }
-
-    return l1;
-}
-
-/* return the total for this list */
-gnc_numeric gncAccountValueTotal (GList *list)
-{
-    gnc_numeric total = gnc_numeric_zero ();
-
-    for ( ; list ; list = list->next)
-    {
-        GncAccountValue *val = list->data;
-        total = gnc_numeric_add (total, val->value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
-    }
-    return total;
-}
-
-/* Destroy a list of accountvalues */
-void gncAccountValueDestroy (GList *list)
-{
-    GList *node;
-    for ( node = list; node ; node = node->next)
-        g_free (node->data);
-
-    g_list_free (list);
-}
-
-/* Package-Private functions */
-
-static void _gncTaxTableCreate (QofBook *book)
-{
-    struct _book_info *bi;
-
-    if (!book) return;
-
-    bi = g_new0 (struct _book_info, 1);
-    qof_book_set_data (book, _GNC_MOD_NAME, bi);
-}
-
-static void _gncTaxTableDestroy (QofBook *book)
-{
-    struct _book_info *bi;
-
-    if (!book) return;
-
-    bi = qof_book_get_data (book, _GNC_MOD_NAME);
-
-    g_list_free (bi->tables);
-    g_free (bi);
-}
-
-static QofObject gncTaxTableDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Tax Table",
-    DI(.create            = ) (gpointer)gncTaxTableCreate,
-    DI(.book_begin        = ) _gncTaxTableCreate,
-    DI(.book_end          = ) _gncTaxTableDestroy,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) NULL,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncTaxTableRegister (void)
-{
-    static QofParam params[] =
-    {
-        { GNC_TT_NAME, 		QOF_TYPE_STRING, 	(QofAccessFunc)gncTaxTableGetName, 		(QofSetterFunc)gncTaxTableSetName },
-        { GNC_TT_REFCOUNT, 	QOF_TYPE_INT64, 	(QofAccessFunc)gncTaxTableGetRefcount, 	(QofSetterFunc)gncTaxTableSetRefcount },
-        { QOF_PARAM_BOOK, 	QOF_ID_BOOK, 		(QofAccessFunc)qof_instance_get_book, 	NULL },
-        { QOF_PARAM_GUID, 	QOF_TYPE_GUID, 		(QofAccessFunc)qof_instance_get_guid, 	NULL },
-        { NULL },
-    };
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params);
-
-    return qof_object_register (&gncTaxTableDesc);
-}
-
-/* need a QOF tax table entry object */
-//gncTaxTableEntrySetType_q int32
-//gint gncTaxTableEntryGetType_q (GncTaxTableEntry *entry);

Deleted: gnucash/trunk/src/business/business-core/gncTaxTable.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,209 +0,0 @@
-/********************************************************************\
- * gncTaxTable.h -- the Gnucash Tax Table interface                 *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup TaxTable
-    @{ */
-/** @file gncTaxTable.h
-    @brief Tax Table programming interface
-    @author Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_TAXTABLE_H_
-#define GNC_TAXTABLE_H_
-
-/** @struct GncTaxTable
-
-modtime is the internal date of the last modtime\n
-See src/doc/business.txt for an explanation of the following\n
-Code that handles refcount, parent, child, invisible and children
-is *identical* to that in ::GncBillTerm
-
- at param	QofInstance     inst;
- at param 	char *          name;
- at param 	GncTaxTableEntryList*  entries;
- at param 	Timespec        modtime;
- at param 	gint64          refcount;
- at param 	GncTaxTable *   parent; if non-null, we are an immutable child
- at param 	GncTaxTable *   child;  if non-null, we have not changed
- at param 	gboolean        invisible;
- at param 	GList *         children; list of children for disconnection
-*/
-typedef struct _gncTaxTable GncTaxTable;
-typedef struct _gncTaxTableClass GncTaxTableClass;
-
-/** @struct GncTaxTableEntry
-
- at param	GncTaxTable *   table;
- at param  Account *       account;
- at param	GncAmountType   type;
- at param	gnc_numeric     amount;
-};
-
-*/
-typedef struct _gncTaxTableEntry GncTaxTableEntry;
-
-typedef struct _gncAccountValue GncAccountValue;
-
-#include "Account.h"
-#include "qof.h"
-#ifdef GNUCASH_MAJOR_VERSION
-#include "gncBusiness.h"
-#endif
-
-#define GNC_ID_TAXTABLE       "gncTaxTable"
-
-/* --- type macros --- */
-#define GNC_TYPE_TAXTABLE            (gnc_taxtable_get_type ())
-#define GNC_TAXTABLE(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))
-#define GNC_TAXTABLE_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))
-#define GNC_IS_TAXTABLE(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))
-#define GNC_IS_TAXTABLE_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))
-#define GNC_TAXTABLE_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
-GType gnc_taxtable_get_type(void);
-
-/**
- * How to interpret the amount.
- * You can interpret it as a VALUE or a PERCENT.
- */
-typedef enum
-{
-    GNC_AMT_TYPE_VALUE = 1, 	/**< tax is a number */
-    GNC_AMT_TYPE_PERCENT		/**< tax is a percentage */
-} GncAmountType;
-
-/** How to interpret the TaxIncluded */
-typedef enum
-{
-    GNC_TAXINCLUDED_YES = 1,  /**< tax is included */
-    GNC_TAXINCLUDED_NO,		/**< tax is not included */
-    GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
-} GncTaxIncluded;
-
-const char * gncAmountTypeToString (GncAmountType type);
-gboolean gncAmountStringToType (const char *str, GncAmountType *type);
-
-const char * gncTaxIncludedTypeToString (GncTaxIncluded type);
-gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type);
-
-/** @name Create/Destroy Functions
- @{ */
-GncTaxTable * gncTaxTableCreate (QofBook *book);
-void gncTaxTableDestroy (GncTaxTable *table);
-GncTaxTableEntry * gncTaxTableEntryCreate (void);
-void gncTaxTableEntryDestroy (GncTaxTableEntry *entry);
-/** @} */
-/** \name Set Functions
-@{
-*/
-void gncTaxTableSetName (GncTaxTable *table, const char *name);
-void gncTaxTableIncRef (GncTaxTable *table);
-void gncTaxTableDecRef (GncTaxTable *table);
-
-void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account);
-void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type);
-void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount);
-/** @} */
-void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry);
-void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry);
-
-void gncTaxTableChanged (GncTaxTable *table);
-void gncTaxTableBeginEdit (GncTaxTable *table);
-void gncTaxTableCommitEdit (GncTaxTable *table);
-gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b);
-
-/** @name Get Functions
- @{ */
-
-/** Return a pointer to the instance gncTaxTable that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncTaxTable * gncTaxTableLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
-}
-
-GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
-
-GList * gncTaxTableGetTables (QofBook *book);
-
-const char *gncTaxTableGetName (const GncTaxTable *table);
-GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
-GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
-#define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
-typedef GList GncTaxTableEntryList;
-GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
-gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
-Timespec gncTaxTableLastModified (const GncTaxTable *table);
-
-Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
-GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
-gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
-/** @} */
-
-int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
-int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
-gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
-
-/************************************************/
-
-struct _gncAccountValue
-{
-    Account *	account;
-    gnc_numeric	value;
-};
-
-/**
- * This will add value to the account-value for acc, creating a new
- * list object if necessary
- */
-GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value);
-
-/** Merge l2 into l1.  l2 is not touched. */
-GList *gncAccountValueAddList (GList *l1, GList *l2);
-
-/** return the total for this list */
-gnc_numeric gncAccountValueTotal (GList *list);
-
-/** Destroy a list of accountvalues */
-void gncAccountValueDestroy (GList *list);
-
-/** QOF parameter definitions */
-#define GNC_TT_NAME "tax table name"
-#define GNC_TT_REFCOUNT "reference count"
-
-/** @deprecated routine */
-#define gncTaxTableGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
-#define gncTaxTableRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
-#define gncTaxTableLookupDirect(G,B) gncTaxTableLookup((B), &(G))
-
-#endif /* GNC_TAXTABLE_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncTaxTableP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTableP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncTaxTableP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,70 +0,0 @@
-/********************************************************************\
- * gncTaxTableP.h -- the Gnucash Tax Table private interface        *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2002 Derek Atkins
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_TAXTABLEP_H_
-#define GNC_TAXTABLEP_H_
-
-#include "gncTaxTable.h"
-
-gboolean gncTaxTableRegister (void);
-
-void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent);
-void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child);
-void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount);
-void gncTaxTableMakeInvisible (GncTaxTable *table);
-
-gboolean gncTaxTableGetInvisible (const GncTaxTable *table);
-
-/** The gncCloneTaxTable() routine makes a copy of the indicated
- *  tax table, placing it in the indicated book.  It copies
- *  the tax table name and list of entries.
- *  It also copies (as needed) both parents and children, so that
- *  the parent-child relationship is correctly mirrored in the
- *  clone.
- * XXX the refcount is mis-handled. This needs fixin....
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book);
-
-/** The gncTaxTableObtainTwin() will find the 'twin' of the
- *  indicated tax table in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneTaxTable()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncTaxTable * gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book);
-
-GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry );
-
-#define gncTaxTableSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
-
-#endif /* GNC_TAXTABLEP_H_ */

Deleted: gnucash/trunk/src/business/business-core/gncVendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.c	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncVendor.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,843 +0,0 @@
-/********************************************************************\
- * gncVendor.c -- the Core Vendor Interface                         *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001, 2002 Derek Atkins
- * Copyright (C) 2003 <linas at linas.org>
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "gnc-commodity.h"
-#include "gncAddressP.h"
-#include "gncBillTermP.h"
-#include "gncInvoice.h"
-#include "gncJobP.h"
-#include "gncTaxTableP.h"
-#include "gncVendor.h"
-#include "gncVendorP.h"
-
-static gint gs_address_event_handler_id = 0;
-static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                                      gpointer user_data, gpointer event_data);
-
-struct _gncVendor
-{
-    QofInstance     inst;
-
-    char *          id;
-    char *          name;
-    char *          notes;
-    GncBillTerm *   terms;
-    GncAddress *    addr;
-    gnc_commodity * currency;
-    GncTaxTable*    taxtable;
-    gboolean        taxtable_override;
-    GncTaxIncluded  taxincluded;
-    gboolean        active;
-    GList *         jobs;
-};
-
-struct _gncVendorClass
-{
-    QofInstanceClass parent_class;
-};
-
-static QofLogModule log_module = GNC_MOD_BUSINESS;
-
-#define _GNC_MOD_NAME        GNC_ID_VENDOR
-
-/* ============================================================ */
-/* Misc inline funcs */
-
-G_INLINE_FUNC void mark_vendor (GncVendor *vendor);
-void mark_vendor (GncVendor *vendor)
-{
-    qof_instance_set_dirty(&vendor->inst);
-    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-/* ============================================================== */
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-/* GObject Initialization */
-G_DEFINE_TYPE(GncVendor, gnc_vendor, QOF_TYPE_INSTANCE);
-
-static void
-gnc_vendor_init(GncVendor* vendor)
-{
-}
-
-static void
-gnc_vendor_dispose(GObject *vendorp)
-{
-    G_OBJECT_CLASS(gnc_vendor_parent_class)->dispose(vendorp);
-}
-
-static void
-gnc_vendor_finalize(GObject* vendorp)
-{
-    G_OBJECT_CLASS(gnc_vendor_parent_class)->finalize(vendorp);
-}
-
-static void
-gnc_vendor_get_property (GObject         *object,
-                         guint            prop_id,
-                         GValue          *value,
-                         GParamSpec      *pspec)
-{
-    GncVendor *vendor;
-
-    g_return_if_fail(GNC_IS_VENDOR(object));
-
-    vendor = GNC_VENDOR(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        g_value_set_string(value, vendor->name);
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-static void
-gnc_vendor_set_property (GObject         *object,
-                         guint            prop_id,
-                         const GValue          *value,
-                         GParamSpec      *pspec)
-{
-    GncVendor *vendor;
-
-    g_return_if_fail(GNC_IS_VENDOR(object));
-
-    vendor = GNC_VENDOR(object);
-    switch (prop_id)
-    {
-    case PROP_NAME:
-        gncVendorSetName(vendor, g_value_get_string(value));
-        break;
-    default:
-        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
-        break;
-    }
-}
-
-/** Return displayable name */
-static gchar*
-impl_get_display_name(const QofInstance* inst)
-{
-    GncVendor* v;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
-
-    v = GNC_VENDOR(inst);
-    return g_strdup_printf("Vendor %s", v->name);
-}
-
-/** Does this object refer to a specific object */
-static gboolean
-impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
-{
-    GncVendor* v;
-
-    g_return_val_if_fail(inst != NULL, FALSE);
-    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
-
-    v = GNC_VENDOR(inst);
-
-    if (GNC_IS_BILLTERM(ref))
-    {
-        return (v->terms == GNC_BILLTERM(ref));
-    }
-    else if (GNC_IS_TAXTABLE(ref))
-    {
-        return (v->taxtable == GNC_TAXTABLE(ref));
-    }
-
-    return FALSE;
-}
-
-/** Returns a list of my type of object which refers to an object.  For example, when called as
-        qof_instance_get_typed_referring_object_list(taxtable, account);
-    it will return the list of taxtables which refer to a specific account.  The result should be the
-    same regardless of which taxtable object is used.  The list must be freed by the caller but the
-    objects on the list must not.
- */
-static GList*
-impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
-{
-    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
-    {
-        return NULL;
-    }
-
-    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
-}
-
-static void
-gnc_vendor_class_init (GncVendorClass *klass)
-{
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
-
-    gobject_class->dispose = gnc_vendor_dispose;
-    gobject_class->finalize = gnc_vendor_finalize;
-    gobject_class->set_property = gnc_vendor_set_property;
-    gobject_class->get_property = gnc_vendor_get_property;
-
-    qof_class->get_display_name = NULL;
-    qof_class->refers_to_object = impl_refers_to_object;
-    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
-
-    g_object_class_install_property
-    (gobject_class,
-     PROP_NAME,
-     g_param_spec_string ("name",
-                          "Vendor Name",
-                          "The vendor name is an arbitrary string "
-                          "assigned by the user to provide the vendor name.",
-                          NULL,
-                          G_PARAM_READWRITE));
-}
-
-/* Create/Destroy Functions */
-GncVendor *gncVendorCreate (QofBook *book)
-{
-    GncVendor *vendor;
-
-    if (!book) return NULL;
-
-    vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
-    qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
-
-    vendor->id = CACHE_INSERT ("");
-    vendor->name = CACHE_INSERT ("");
-    vendor->notes = CACHE_INSERT ("");
-    vendor->addr = gncAddressCreate (book, &vendor->inst);
-    vendor->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
-    vendor->active = TRUE;
-    vendor->jobs = NULL;
-
-    if (gs_address_event_handler_id == 0)
-    {
-        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
-    }
-
-    qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
-
-    return vendor;
-}
-
-void gncVendorDestroy (GncVendor *vendor)
-{
-    if (!vendor) return;
-    qof_instance_set_destroying(vendor, TRUE);
-    gncVendorCommitEdit (vendor);
-}
-
-static void gncVendorFree (GncVendor *vendor)
-{
-    if (!vendor) return;
-
-    qof_event_gen (&vendor->inst, QOF_EVENT_DESTROY, NULL);
-
-    CACHE_REMOVE (vendor->id);
-    CACHE_REMOVE (vendor->name);
-    CACHE_REMOVE (vendor->notes);
-    gncAddressBeginEdit (vendor->addr);
-    gncAddressDestroy (vendor->addr);
-    g_list_free (vendor->jobs);
-
-    if (vendor->terms)
-        gncBillTermDecRef (vendor->terms);
-    if (vendor->taxtable)
-        gncTaxTableDecRef (vendor->taxtable);
-
-    /* qof_instance_release (&vendor->inst); */
-    g_object_unref (vendor);
-}
-
-/** Create a copy of a vendor, placing the copy into a new book. */
-GncVendor *
-gncCloneVendor (GncVendor *from, QofBook *book)
-{
-    GList *node;
-    GncVendor *vendor;
-
-    if (!book) return NULL;
-
-    vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
-    qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
-    qof_instance_gemini (&vendor->inst, &from->inst);
-
-    vendor->id = CACHE_INSERT (from->id);
-    vendor->name = CACHE_INSERT (from->name);
-    vendor->notes = CACHE_INSERT (from->notes);
-    vendor->addr = gncCloneAddress (from->addr, &vendor->inst, book);
-    vendor->taxincluded = from->taxincluded;
-    vendor->taxtable_override = from->taxtable_override;
-    vendor->active = from->active;
-
-    vendor->terms = gncBillTermObtainTwin (from->terms, book);
-    gncBillTermIncRef (vendor->terms);
-
-    vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
-
-    vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
-    gncTaxTableIncRef (vendor->taxtable);
-
-    vendor->jobs = NULL;
-    for (node = g_list_last(from->jobs); node; node = node->prev)
-    {
-        GncJob *job = node->data;
-        job = gncJobObtainTwin (job, book);
-        vendor->jobs = g_list_prepend(vendor->jobs, job);
-    }
-
-    qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
-
-    return vendor;
-}
-
-GncVendor *
-gncVendorObtainTwin (GncVendor *from, QofBook *book)
-{
-    GncVendor *vendor;
-    if (!book) return NULL;
-
-    vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
-    if (!vendor)
-    {
-        vendor = gncCloneVendor (from, book);
-    }
-
-    return vendor;
-}
-
-/* ============================================================== */
-/* Set Functions */
-
-#define SET_STR(obj, member, str) { \
-        char * tmp; \
-        \
-        if (!safe_strcmp (member, str)) return; \
-        gncVendorBeginEdit (obj); \
-        tmp = CACHE_INSERT (str); \
-        CACHE_REMOVE (member); \
-        member = tmp; \
-        }
-
-void gncVendorSetID (GncVendor *vendor, const char *id)
-{
-    if (!vendor) return;
-    if (!id) return;
-    SET_STR(vendor, vendor->id, id);
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetName (GncVendor *vendor, const char *name)
-{
-    if (!vendor) return;
-    if (!name) return;
-    SET_STR(vendor, vendor->name, name);
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetNotes (GncVendor *vendor, const char *notes)
-{
-    if (!vendor) return;
-    if (!notes) return;
-    SET_STR(vendor, vendor->notes, notes);
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
-{
-    if (!vendor) return;
-    if (vendor->terms == terms) return;
-
-    gncVendorBeginEdit (vendor);
-    if (vendor->terms)
-        gncBillTermDecRef (vendor->terms);
-    vendor->terms = terms;
-    if (vendor->terms)
-        gncBillTermIncRef (vendor->terms);
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl)
-{
-    if (!vendor) return;
-    if (taxincl == vendor->taxincluded) return;
-    gncVendorBeginEdit (vendor);
-    vendor->taxincluded = taxincl;
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency)
-{
-    if (!vendor || !currency) return;
-    if (vendor->currency &&
-            gnc_commodity_equal (vendor->currency, currency))
-        return;
-    gncVendorBeginEdit (vendor);
-    vendor->currency = currency;
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetActive (GncVendor *vendor, gboolean active)
-{
-    if (!vendor) return;
-    if (active == vendor->active) return;
-    gncVendorBeginEdit (vendor);
-    vendor->active = active;
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override)
-{
-    if (!vendor) return;
-    if (vendor->taxtable_override == override) return;
-    gncVendorBeginEdit (vendor);
-    vendor->taxtable_override = override;
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table)
-{
-    if (!vendor) return;
-    if (vendor->taxtable == table) return;
-    gncVendorBeginEdit (vendor);
-    if (vendor->taxtable)
-        gncTaxTableDecRef (vendor->taxtable);
-    if (table)
-        gncTaxTableIncRef (table);
-    vendor->taxtable = table;
-    mark_vendor (vendor);
-    gncVendorCommitEdit (vendor);
-}
-
-static void
-qofVendorSetAddr (GncVendor *vendor, QofInstance *addr_ent)
-{
-    GncAddress *addr;
-
-    if (!vendor || !addr_ent)
-    {
-        return;
-    }
-    addr = (GncAddress*)addr_ent;
-    if (addr == vendor->addr)
-    {
-        return;
-    }
-    if (vendor->addr != NULL)
-    {
-        gncAddressBeginEdit(vendor->addr);
-        gncAddressDestroy(vendor->addr);
-    }
-    gncVendorBeginEdit(vendor);
-    vendor->addr = addr;
-    gncVendorCommitEdit(vendor);
-}
-
-static void
-qofVendorSetTaxIncluded(GncVendor *vendor, const char* type_string)
-{
-    GncTaxIncluded inc;
-
-    if (!gncTaxIncludedStringToType(type_string, &inc))
-    {
-        return;
-    }
-    gncVendorBeginEdit(vendor);
-    vendor->taxincluded = inc;
-    gncVendorCommitEdit(vendor);
-}
-
-/* ============================================================== */
-/* Get Functions */
-
-const char * gncVendorGetID (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->id;
-}
-
-const char * gncVendorGetName (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->name;
-}
-
-GncAddress * gncVendorGetAddr (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->addr;
-}
-
-const char * gncVendorGetNotes (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->notes;
-}
-
-GncBillTerm * gncVendorGetTerms (const GncVendor *vendor)
-{
-    if (!vendor) return 0;
-    return vendor->terms;
-}
-
-GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor)
-{
-    if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
-    return vendor->taxincluded;
-}
-
-gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->currency;
-}
-
-gboolean gncVendorGetActive (const GncVendor *vendor)
-{
-    if (!vendor) return FALSE;
-    return vendor->active;
-}
-
-gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor)
-{
-    if (!vendor) return FALSE;
-    return vendor->taxtable_override;
-}
-
-GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor)
-{
-    if (!vendor) return NULL;
-    return vendor->taxtable;
-}
-
-static const char*
-qofVendorGetTaxIncluded(const GncVendor *vendor)
-{
-    return gncTaxIncludedTypeToString(vendor->taxincluded);
-}
-
-/* Note that JobList changes do not affect the "dirtiness" of the vendor */
-void gncVendorAddJob (GncVendor *vendor, GncJob *job)
-{
-    if (!vendor) return;
-    if (!job) return;
-
-    if (g_list_index(vendor->jobs, job) == -1)
-        vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
-                                             (GCompareFunc)gncJobCompare);
-
-    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
-{
-    GList *node;
-
-    if (!vendor) return;
-    if (!job) return;
-
-    node = g_list_find (vendor->jobs, job);
-    if (!node)
-    {
-        /*    PERR ("split not in account"); */
-    }
-    else
-    {
-        vendor->jobs = g_list_remove_link (vendor->jobs, node);
-        g_list_free_1 (node);
-    }
-
-    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
-}
-
-void gncVendorBeginEdit (GncVendor *vendor)
-{
-    qof_begin_edit(&vendor->inst);
-}
-
-static void gncVendorOnError (QofInstance *vendor, QofBackendError errcode)
-{
-    PERR("Vendor QofBackend Failure: %d", errcode);
-    gnc_engine_signal_commit_error( errcode );
-}
-
-static void gncVendorOnDone (QofInstance *inst)
-{
-    GncVendor *vendor = (GncVendor *) inst;
-    gncAddressClearDirty (vendor->addr);
-}
-
-static void vendor_free (QofInstance *inst)
-{
-    GncVendor *vendor = (GncVendor *) inst;
-    gncVendorFree (vendor);
-}
-
-void gncVendorCommitEdit (GncVendor *vendor)
-{
-    if (!qof_commit_edit (QOF_INSTANCE(vendor))) return;
-    qof_commit_edit_part2 (&vendor->inst, gncVendorOnError,
-                           gncVendorOnDone, vendor_free);
-}
-
-/* ============================================================== */
-/* Other functions */
-
-int gncVendorCompare (const GncVendor *a, const GncVendor *b)
-{
-    if (!a && !b) return 0;
-    if (!a && b) return 1;
-    if (a && !b) return -1;
-
-    return(strcmp(a->name, b->name));
-}
-
-gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
-{
-    if (a == NULL && b == NULL) return TRUE;
-    if (a == NULL ||  b == NULL) return FALSE;
-
-    g_return_val_if_fail(GNC_IS_VENDOR(a), FALSE);
-    g_return_val_if_fail(GNC_IS_VENDOR(b), FALSE);
-
-    if (safe_strcmp(a->id, b->id) != 0)
-    {
-        PWARN("IDs differ: %s vs %s", a->id, b->id);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->name, b->name) != 0)
-    {
-        PWARN("Names differ: %s vs %s", a->name, b->name);
-        return FALSE;
-    }
-
-    if (safe_strcmp(a->notes, b->notes) != 0)
-    {
-        PWARN("Notes differ");
-        return FALSE;
-    }
-
-    if (!gncBillTermEqual(a->terms, b->terms))
-    {
-        PWARN("BillTerms differ");
-        return FALSE;
-    }
-
-    if (!gncAddressEqual(a->addr, b->addr))
-    {
-        PWARN("Addresses differ");
-        return FALSE;
-    }
-
-    if (!gnc_commodity_equal(a->currency, b->currency))
-    {
-        PWARN("Currencies differ");
-        return FALSE;
-    }
-
-    if (!gncTaxTableEqual(a->taxtable, b->taxtable))
-    {
-        PWARN("Tax tables differ");
-        return FALSE;
-    }
-
-    if (a->taxtable_override != b->taxtable_override)
-    {
-        PWARN("Tax table override flags differ");
-        return FALSE;
-    }
-
-    if (a->taxincluded != b->taxincluded)
-    {
-        PWARN("Tax included flags differ");
-        return FALSE;
-    }
-
-    if (a->active != b->active)
-    {
-        PWARN("Active flags differ");
-        return FALSE;
-    }
-
-//    GList *         jobs;
-    return TRUE;
-}
-
-GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
-{
-    if (!vendor) return NULL;
-
-    if (show_all)
-    {
-        return (g_list_copy (vendor->jobs));
-    }
-    else
-    {
-        GList *list = NULL, *iterator;
-        for (iterator = vendor->jobs; iterator; iterator = iterator->next)
-        {
-            GncJob *j = iterator->data;
-            if (gncJobGetActive (j))
-                list = g_list_append (list, j);
-        }
-        return list;
-    }
-}
-
-gboolean gncVendorIsDirty (const GncVendor *vendor)
-{
-    if (!vendor) return FALSE;
-    return (qof_instance_get_dirty_flag(vendor)
-            || gncAddressIsDirty (vendor->addr));
-}
-
-/**
- * Listens for MODIFY events from addresses.   If the address belongs to a vendor,
- * mark the vendor as dirty.
- *
- * @param entity Entity for the event
- * @param event_type Event type
- * @param user_data User data registered with the handler
- * @param event_data Event data passed with the event.
- */
-static void
-listen_for_address_events(QofInstance *entity, QofEventId event_type,
-                          gpointer user_data, gpointer event_data)
-{
-    GncVendor* v;
-
-    if ((event_type & QOF_EVENT_MODIFY) == 0)
-    {
-        return;
-    }
-    if (!GNC_IS_ADDRESS(entity))
-    {
-        return;
-    }
-    if (!GNC_IS_VENDOR(event_data))
-    {
-        return;
-    }
-    v = GNC_VENDOR(event_data);
-    gncVendorBeginEdit(v);
-    mark_vendor(v);
-    gncVendorCommitEdit(v);
-}
-/* ============================================================== */
-/* Package-Private functions */
-
-static const char * _gncVendorPrintable (gpointer item)
-{
-    GncVendor *v = item;
-    if (!item) return NULL;
-    return v->name;
-}
-
-static QofObject gncVendorDesc =
-{
-    DI(.interface_version = ) QOF_OBJECT_VERSION,
-    DI(.e_type            = ) _GNC_MOD_NAME,
-    DI(.type_label        = ) "Vendor",
-    DI(.create            = ) (gpointer)gncVendorCreate,
-    DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
-    DI(.is_dirty          = ) qof_collection_is_dirty,
-    DI(.mark_clean        = ) qof_collection_mark_clean,
-    DI(.foreach           = ) qof_collection_foreach,
-    DI(.printable         = ) _gncVendorPrintable,
-    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean gncVendorRegister (void)
-{
-    static QofParam params[] =
-    {
-        { VENDOR_ID, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetID, (QofSetterFunc)gncVendorSetID },
-        { VENDOR_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetName, (QofSetterFunc)gncVendorSetName },
-        { VENDOR_ADDR,    GNC_ID_ADDRESS, (QofAccessFunc)gncVendorGetAddr, (QofSetterFunc)qofVendorSetAddr },
-        { VENDOR_NOTES,   QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetNotes, (QofSetterFunc)gncVendorSetNotes },
-        { VENDOR_TERMS,   GNC_ID_BILLTERM, (QofAccessFunc)gncVendorGetTerms, (QofSetterFunc)gncVendorSetTerms },
-        {
-            VENDOR_TAX_OVERRIDE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetTaxTableOverride,
-            (QofSetterFunc)gncVendorSetTaxTableOverride
-        },
-        {
-            VENDOR_TAX_TABLE, GNC_ID_TAXTABLE, (QofAccessFunc)gncVendorGetTaxTable,
-            (QofSetterFunc)gncVendorSetTaxTable
-        },
-        {
-            VENDOR_TAX_INC, QOF_TYPE_STRING, (QofAccessFunc)qofVendorGetTaxIncluded,
-            (QofSetterFunc)qofVendorSetTaxIncluded
-        },
-        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
-        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
-        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetActive, NULL },
-        { NULL },
-    };
-
-    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_VENDOR, INVOICE_OWNER))
-    {
-        return FALSE;
-    }
-    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_VENDOR, JOB_OWNER))
-    {
-        return FALSE;
-    }
-
-    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params);
-
-    return qof_object_register (&gncVendorDesc);
-}
-
-gint64 gncVendorNextID (QofBook *book)
-{
-    return qof_book_get_counter (book, _GNC_MOD_NAME);
-}

Deleted: gnucash/trunk/src/business/business-core/gncVendor.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncVendor.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,139 +0,0 @@
-/********************************************************************\
- * gncVendor.h -- the Core Vendor Interface                         *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-/** @addtogroup Business
-    @{ */
-/** @addtogroup Vendor
-    @{ */
-/** @file gncVendor.h
-    @brief  Vendor Interface
-    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
-*/
-
-#ifndef GNC_VENDOR_H_
-#define GNC_VENDOR_H_
-
-typedef struct _gncVendor GncVendor;
-typedef struct _gncVendorClass GncVendorClass;
-
-#include "gncAddress.h"
-#include "gncBillTerm.h"
-#include "gncTaxTable.h"
-#include "gncJob.h"
-
-#define GNC_ID_VENDOR       "gncVendor"
-
-/* --- type macros --- */
-#define GNC_TYPE_VENDOR            (gnc_vendor_get_type ())
-#define GNC_VENDOR(o)              \
-     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_VENDOR, GncVendor))
-#define GNC_VENDOR_CLASS(k)        \
-     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_VENDOR, GncVendorClass))
-#define GNC_IS_VENDOR(o)           \
-     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_VENDOR))
-#define GNC_IS_VENDOR_CLASS(k)     \
-     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_VENDOR))
-#define GNC_VENDOR_GET_CLASS(o)    \
-     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_VENDOR, GncVendorClass))
-GType gnc_vendor_get_type(void);
-
-/* Create/Destroy Functions */
-
-GncVendor *gncVendorCreate (QofBook *book);
-void gncVendorDestroy (GncVendor *vendor);
-
-/** @name Set Functions
- @{
-*/
-
-void gncVendorSetID (GncVendor *vendor, const char *id);
-void gncVendorSetName (GncVendor *vendor, const char *name);
-void gncVendorSetNotes (GncVendor *vendor, const char *notes);
-void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms);
-void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl);
-void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency);
-void gncVendorSetActive (GncVendor *vendor, gboolean active);
-void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override);
-void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table);
-
-/** @} */
-
-void gncVendorAddJob (GncVendor *vendor, GncJob *job);
-void gncVendorRemoveJob (GncVendor *vendor, GncJob *job);
-
-void gncVendorBeginEdit (GncVendor *vendor);
-void gncVendorCommitEdit (GncVendor *vendor);
-
-/** @name Get Functions
-@{
-*/
-
-const char * gncVendorGetID (const GncVendor *vendor);
-const char * gncVendorGetName (const GncVendor *vendor);
-GncAddress * gncVendorGetAddr (const GncVendor *vendor);
-const char * gncVendorGetNotes (const GncVendor *vendor);
-GncBillTerm * gncVendorGetTerms (const GncVendor *vendor);
-GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor);
-gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor);
-gboolean gncVendorGetActive (const GncVendor *vendor);
-
-gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor);
-GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor);
-
-/** @} */
-/** XXX should be renamed to RetJobList to be consistent with
- * other usage, since caller must free the copied list
- */
-GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all);
-gboolean gncVendorIsDirty (const GncVendor *vendor);
-int gncVendorCompare (const GncVendor *a, const GncVendor *b);
-gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b);
-
-/** Return a pointer to the instance gncVendor that is identified
- *  by the guid, and is residing in the book. Returns NULL if the
- *  instance can't be found.
- *  Equivalent function prototype is
- *  GncVendor * gncVendorLookup (QofBook *book, const GncGUID *guid);
- */
-static inline GncVendor * gncVendorLookup (const QofBook *book, const GncGUID *guid)
-{
-    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_VENDOR, GncVendor);
-}
-
-#define VENDOR_ID	"id"
-#define VENDOR_NAME	"name"
-#define VENDOR_ADDR	"addr"
-#define VENDOR_NOTES "vendor_notes"
-#define VENDOR_TERMS "vendor_terms"
-#define VENDOR_TAX_INC "vendor_tax_included"
-#define VENDOR_ACTIVE "vendor_is_active"
-#define VENDOR_TAX_OVERRIDE "override_tax_table"
-#define VENDOR_TAX_TABLE "vendor_tax_table"
-
-/** deprecated functions */
-#define gncVendorGetBook(X) qof_instance_get_book (QOF_INSTANCE(X))
-#define gncVendorGetGUID(X) qof_instance_get_guid (QOF_INSTANCE(X))
-#define gncVendorRetGUID(X) (X ? *(qof_instance_get_guid (QOF_INSTANCE(X))) : *(guid_null()))
-#define gncVendorLookupDirect(G,B) gncVendorLookup((B),&(G))
-
-#endif /* GNC_VENDOR_H_ */
-/** @} */
-/** @} */

Deleted: gnucash/trunk/src/business/business-core/gncVendorP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendorP.h	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/business/business-core/gncVendorP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -1,58 +0,0 @@
-/********************************************************************\
- * gncVendorP.h -- the Core Vendor Interface                        *
- *                                                                  *
- * 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       *
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
- * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
- *                                                                  *
-\********************************************************************/
-
-/*
- * Copyright (C) 2001 Derek Atkins
- * Author: Derek Atkins <warlord at MIT.EDU>
- */
-
-#ifndef GNC_VENDORP_H_
-#define GNC_VENDORP_H_
-
-#include "gncVendor.h"
-
-gboolean gncVendorRegister (void);
-gint64 gncVendorNextID (QofBook *book);
-
-/** The gncCloneVendor() routine makes a copy of the indicated
- *  vendor, placing it in the indicated book.  It copies
- *  the name, notes, address, etc.
- *  It then adds a pair of 'gemini' kvp pointers so that each copy
- *  can be found from the other.
- */
-
-GncVendor * gncCloneVendor (GncVendor *from, QofBook *);
-
-/** The gncVendorObtainTwin() will find the 'twin' of the
- *  indicated vendor in the indicated book.  If the twin doesn't
- *  yet exist in the book, it will be created (by calling
- *  gncCloneVendor()) and placed into the book.
- *
- * We called this routine 'Obtain' instead of "Get" to distinguish
- * it from the other Get routines, which work in fundamentally
- * different ways.
- */
-GncVendor * gncVendorObtainTwin (GncVendor *from, QofBook *book);
-#define gncVendorSetGUID(V,G) qof_instance_set_guid(QOF_INSTANCE(V),(G))
-
-
-#endif /* GNC_VENDORP_H_ */

Modified: gnucash/trunk/src/engine/CMakeLists.txt
===================================================================
--- gnucash/trunk/src/engine/CMakeLists.txt	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/engine/CMakeLists.txt	2010-07-03 21:53:22 UTC (rev 19329)
@@ -50,12 +50,39 @@
   gncObject.h
   kvp-scm.h
   policy.h
+  gncAddress.h
+  gncAddressP.h
+  gncBillTerm.h
+  gncBillTermP.h
+  gncBusGuile.h
+  gncBusiness.h
+  gncCustomer.h
+  gncCustomerP.h
+  gncEmployee.h
+  gncEmployeeP.h
+  gncEntry.h
+  gncEntryP.h
+  gncInvoice.h
+  gncInvoiceP.h
+  gncJob.h
+  gncJobP.h
+  gncOrder.h
+  gncOrderP.h
+  gncOwner.h
+  gncOwnerP.h
+  gncTaxTable.h
+  gncTaxTableP.h
+  gncVendor.h
+  gncVendorP.h
 )
 
 # Command to generate the swig-engine.c wrapper file
 SET (SWIG_ENGINE_C ${CMAKE_CURRENT_BINARY_DIR}/swig-engine.c)
 GNC_ADD_SWIG_COMMAND (${SWIG_ENGINE_C} ${CMAKE_CURRENT_SOURCE_DIR}/engine.i)
 
+SET (SWIG_BUSINESS_CORE_C ${CMAKE_CURRENT_BINARY_DIR}/swig-business-core.c)
+GNC_ADD_SWIG_COMMAND (${SWIG_BUSINESS_CORE_C} ${CMAKE_CURRENT_SOURCE_DIR}/business-core.i)
+
 # Command to generate the iso-4217-currencies.c file
 SET (ISO_4217_C ${CMAKE_CURRENT_BINARY_DIR}/iso-4217-currencies.c)
 ADD_CUSTOM_COMMAND (
@@ -108,6 +135,20 @@
   glib-helpers.c
   policy.c
   ${SWIG_ENGINE_C}
+  gncAddress.c
+  gncBillTerm.c
+  gncBusGuile.c
+  gncBusiness.c
+  gncCustomer.c
+  gncEmployee.c
+  gncEntry.c
+  gncInvoice.c
+  gncJob.c
+  gncOrder.c
+  gncOwner.c
+  gncTaxTable.c
+  gncVendor.c
+  ${SWIG_BUSINESS_CORE_C}
 )
 
 # Add dependency on config.h

Modified: gnucash/trunk/src/engine/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/Makefile.am	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/engine/Makefile.am	2010-07-03 21:53:22 UTC (rev 19329)
@@ -42,7 +42,21 @@
   kvp-scm.c \
   engine-helpers.c \
   glib-helpers.c  \
-  policy.c
+  policy.c \
+  swig-business-core.c \
+  gncBusGuile.c \
+  gncAddress.c \
+  gncBillTerm.c \
+  gncBusiness.c \
+  gncCustomer.c \
+  gncEmployee.c \
+  gncEntry.c \
+  gncInvoice.c \
+  gncJob.c \
+  gncOrder.c \
+  gncOwner.c \
+  gncTaxTable.c \
+  gncVendor.c
 
 EXTRA_libgncmod_engine_la_SOURCES = iso-4217-currencies.c
 
@@ -81,7 +95,31 @@
   gnc-session-scm.h \
   gncObject.h \
   kvp-scm.h \
-  policy.h
+  policy.h \
+  gncAddress.h \
+  gncAddressP.h \
+  gncBillTerm.h \
+  gncBillTermP.h \
+  gncBusiness.h \
+  gncBusGuile.h \
+  gncCustomer.h \
+  gncCustomerP.h \
+  gncEmployee.h \
+  gncEmployeeP.h \
+  gncEntry.h \
+  gncEntryP.h \
+  gncInvoice.h \
+  gncInvoiceP.h \
+  gncJob.h \
+  gncJobP.h \
+  gncOrder.h \
+  gncOrderP.h \
+  gncOwner.h \
+  gncOwnerP.h \
+  gncTaxTable.h \
+  gncTaxTableP.h \
+  gncVendor.h \
+  gncVendorP.h
 
 noinst_HEADERS = \
   AccountP.h \
@@ -129,6 +167,7 @@
   kvp_doc.txt \
   SX-book-p.h \
   engine.i \
+  business-core.i \
   ${gncmod_DATA} \
   ${gncscm_DATA}
 
@@ -162,6 +201,10 @@
                ${gncinclude_HEADERS} ${noinst_HEADERS}
 	$(SWIG) -guile $(SWIG_ARGS) -Linkage module \
 	-I${top_srcdir}/src/libqof/qof -I${top_srcdir}/src -o $@ $<
+swig-business-core.c: business-core.i ${noinst_HEADERS} \
+                      ${top_srcdir}/src/base-typemaps.i
+	$(SWIG) -guile $(SWIG_ARGS) -Linkage module \
+	-I${top_srcdir}/src -o $@ $<
 endif
 
 iso-4217-currencies.c: iso-4217-currencies.scm iso-currencies-to-c
@@ -172,6 +215,6 @@
 
 CLEANFILES = $(BUILT_SOURCES) gnucash .scm-links \
 	${SCM_FILE_LINKS}
-MAINTAINERCLEANFILES = swig-engine.c
+MAINTAINERCLEANFILES = swig-engine.c swig-business-core.c
 
 INCLUDES = -DG_LOG_DOMAIN=\"gnc.engine\"

Copied: gnucash/trunk/src/engine/business-core.i (from rev 19328, gnucash/trunk/src/business/business-core/business-core.i)
===================================================================
--- gnucash/trunk/src/engine/business-core.i	                        (rev 0)
+++ gnucash/trunk/src/engine/business-core.i	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,168 @@
+%module sw_business_core
+%{
+/* Includes the header in the wrapper code */
+#include <config.h>
+#include <guile-mappings.h>
+#include <gncAddress.h>
+#include <gncBillTerm.h>
+#include <gncCustomer.h>
+#include <gncEmployee.h>
+#include <gncEntry.h>
+#include <gncInvoice.h>
+#include <gncJob.h>
+#include <gncOrder.h>
+#include <gncOwner.h>
+#include <gncTaxTable.h>
+#include <gncVendor.h>
+#include <gncBusGuile.h>
+#ifdef _MSC_VER
+# define snprintf _snprintf
+#endif
+#include "engine-helpers.h"
+#include "gncBusGuile.h"
+
+/* Disable -Waddress.  GCC 4.2 warns (and fails to compile with -Werror) when
+ * passing the address of a guid on the stack to QOF_BOOK_LOOKUP_ENTITY via
+ * gncInvoiceLookup and friends.  When the macro gets inlined, the compiler
+ * emits a warning that the guid null pointer test is always true.
+ */
+#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
+#    pragma GCC diagnostic warning "-Waddress"
+#endif
+
+SCM scm_init_sw_business_core_module (void);
+%}
+
+%import "base-typemaps.i"
+
+%rename(gncOwnerReturnGUID) gncOwnerRetGUID;
+
+%inline %{
+static GncGUID gncTaxTableReturnGUID(GncTaxTable *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncGUID gncInvoiceReturnGUID(GncInvoice *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncGUID gncJobReturnGUID(GncJob *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncGUID gncVendorReturnGUID(GncVendor *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncGUID gncCustomerReturnGUID(GncCustomer *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncGUID gncEmployeeReturnGUID(GncEmployee *x)
+{ return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
+
+static GncTaxTable * gncTaxTableLookupFlip(GncGUID g, QofBook *b)
+{ return gncTaxTableLookup(b, &g); }
+
+static GncInvoice * gncInvoiceLookupFlip(GncGUID g, QofBook *b)
+{ return gncInvoiceLookup(b, &g); }
+
+static GncJob * gncJobLookupFlip(GncGUID g, QofBook *b)
+{ return gncJobLookup(b, &g); }
+
+static GncVendor * gncVendorLookupFlip(GncGUID g, QofBook *b)
+{ return gncVendorLookup(b, &g); }
+
+static GncCustomer * gncCustomerLookupFlip(GncGUID g, QofBook *b)
+{ return gncCustomerLookup(b, &g); }
+
+static GncEmployee * gncEmployeeLookupFlip(GncGUID g, QofBook *b)
+{ return gncEmployeeLookup(b, &g); }
+
+%}
+
+GLIST_HELPER_INOUT(EntryList, SWIGTYPE_p__gncEntry);
+GLIST_HELPER_INOUT(GncTaxTableEntryList, SWIGTYPE_p__gncTaxTableEntry);
+
+%typemap(in) GncAccountValue * "$1 = gnc_scm_to_account_value_ptr($input);"
+%typemap(out) GncAccountValue * "$result = gnc_account_value_ptr_to_scm($1);"
+%typemap(in) AccountValueList * {
+  SCM list = $input;
+  GList *c_list = NULL;
+
+  while (!scm_is_null(list)) {
+        GncAccountValue *p;
+
+        SCM p_scm = SCM_CAR(list);
+        if (scm_is_false(p_scm) || scm_is_null(p_scm))
+           p = NULL;
+        else
+           p = gnc_scm_to_account_value_ptr(p_scm);
+
+        c_list = g_list_prepend(c_list, p);
+        list = SCM_CDR(list);
+  }
+
+  $1 = g_list_reverse(c_list);
+}
+%typemap(out) AccountValueList * {
+  SCM list = SCM_EOL;
+  GList *node;
+
+  for (node = $1; node; node = node->next)
+    list = scm_cons(gnc_account_value_ptr_to_scm(node->data), list);
+
+  $result = scm_reverse(list);
+}
+
+
+
+/* Parse the header files to generate wrappers */
+%include <gncAddress.h>
+%include <gncBillTerm.h>
+%include <gncCustomer.h>
+%include <gncEmployee.h>
+%include <gncEntry.h>
+%include <gncInvoice.h>
+%include <gncJob.h>
+%include <gncOrder.h>
+%include <gncOwner.h>
+%include <gncTaxTable.h>
+%include <gncVendor.h>
+%include <gncBusGuile.h>
+
+#define URL_TYPE_CUSTOMER GNC_ID_CUSTOMER
+#define URL_TYPE_VENDOR GNC_ID_VENDOR
+#define URL_TYPE_EMPLOYEE GNC_ID_EMPLOYEE
+#define URL_TYPE_JOB GNC_ID_JOB
+#define URL_TYPE_INVOICE GNC_ID_INVOICE
+// not exactly clean
+#define URL_TYPE_OWNERREPORT "owner-report"
+
+%init {
+  {
+    char tmp[100];
+
+#define SET_ENUM(e) snprintf(tmp, 100, "(set! %s (%s))", (e), (e));  \
+    scm_c_eval_string(tmp);
+
+    SET_ENUM("GNC-OWNER-CUSTOMER");
+    SET_ENUM("GNC-OWNER-VENDOR");
+    SET_ENUM("GNC-OWNER-EMPLOYEE");
+    SET_ENUM("GNC-OWNER-JOB");
+    SET_ENUM("GNC-AMT-TYPE-VALUE");
+    SET_ENUM("GNC-AMT-TYPE-PERCENT");
+
+    SET_ENUM("URL-TYPE-CUSTOMER");
+    SET_ENUM("URL-TYPE-VENDOR");
+    SET_ENUM("URL-TYPE-EMPLOYEE");
+    SET_ENUM("URL-TYPE-JOB");
+    SET_ENUM("URL-TYPE-INVOICE");
+    SET_ENUM("URL-TYPE-OWNERREPORT");
+
+    SET_ENUM("INVOICE-FROM-TXN");
+    SET_ENUM("INVOICE-FROM-LOT");
+    SET_ENUM("INVOICE-OWNER");
+    SET_ENUM("OWNER-PARENTG");
+    SET_ENUM("OWNER-FROM-LOT");
+
+
+#undefine SET_ENUM
+  }
+
+}

Copied: gnucash/trunk/src/engine/gncAddress.c (from rev 19328, gnucash/trunk/src/business/business-core/gncAddress.c)
===================================================================
--- gnucash/trunk/src/engine/gncAddress.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncAddress.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,691 @@
+/********************************************************************\
+ * gncAddress.c -- an Address object                                *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "gncAddress.h"
+#include "gncAddressP.h"
+#include "gncCustomerP.h"
+
+struct _gncAddress
+{
+    QofInstance inst;
+
+    QofBook *	book;
+    QofInstance * parent;
+    gboolean	dirty;
+    char *	name;
+    char *	addr1;
+    char *	addr2;
+    char *	addr3;
+    char *	addr4;
+    char *	phone;
+    char *	fax;
+    char *	email;
+};
+
+struct _gncAddressClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME	GNC_ADDRESS_MODULE_NAME
+
+G_INLINE_FUNC void mark_address (GncAddress *address);
+void mark_address (GncAddress *address)
+{
+    address->dirty = TRUE;
+
+    qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
+    qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
+}
+
+enum
+{
+    PROP_0,
+    PROP_NAME,
+    PROP_ADDR1,
+    PROP_ADDR2,
+    PROP_ADDR3,
+    PROP_ADDR4,
+    PROP_PHONE,
+    PROP_FAX,
+    PROP_EMAIL
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncAddress, gnc_address, QOF_TYPE_INSTANCE);
+
+static void
+gnc_address_init(GncAddress* addr)
+{
+}
+
+static void
+gnc_address_dispose(GObject *addrp)
+{
+    G_OBJECT_CLASS(gnc_address_parent_class)->dispose(addrp);
+}
+
+static void
+gnc_address_finalize(GObject* addrp)
+{
+    G_OBJECT_CLASS(gnc_address_parent_class)->finalize(addrp);
+}
+
+static void
+gnc_address_get_property (GObject         *object,
+                          guint            prop_id,
+                          GValue          *value,
+                          GParamSpec      *pspec)
+{
+    GncAddress *address;
+
+    g_return_if_fail(GNC_IS_ADDRESS(object));
+
+    address = GNC_ADDRESS(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, address->name);
+        break;
+    case PROP_ADDR1:
+        g_value_set_string(value, address->addr1);
+        break;
+    case PROP_ADDR2:
+        g_value_set_string(value, address->addr2);
+        break;
+    case PROP_ADDR3:
+        g_value_set_string(value, address->addr3);
+        break;
+    case PROP_ADDR4:
+        g_value_set_string(value, address->addr4);
+        break;
+    case PROP_PHONE:
+        g_value_set_string(value, address->phone);
+        break;
+    case PROP_FAX:
+        g_value_set_string(value, address->fax);
+        break;
+    case PROP_EMAIL:
+        g_value_set_string(value, address->email);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_address_set_property (GObject         *object,
+                          guint            prop_id,
+                          const GValue          *value,
+                          GParamSpec      *pspec)
+{
+    GncAddress *address;
+
+    g_return_if_fail(GNC_IS_ADDRESS(object));
+
+    address = GNC_ADDRESS(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncAddressSetName(address, g_value_get_string(value));
+        break;
+    case PROP_ADDR1:
+        gncAddressSetAddr1(address, g_value_get_string(value));
+        break;
+    case PROP_ADDR2:
+        gncAddressSetAddr2(address, g_value_get_string(value));
+        break;
+    case PROP_ADDR3:
+        gncAddressSetAddr3(address, g_value_get_string(value));
+        break;
+    case PROP_ADDR4:
+        gncAddressSetAddr4(address, g_value_get_string(value));
+        break;
+    case PROP_PHONE:
+        gncAddressSetPhone(address, g_value_get_string(value));
+        break;
+    case PROP_FAX:
+        gncAddressSetFax(address, g_value_get_string(value));
+        break;
+    case PROP_EMAIL:
+        gncAddressSetEmail(address, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing.  The parent field doesn't really count since the parent knows which address
+       belongs to it. */
+    return NULL;
+}
+
+static void
+gnc_address_class_init (GncAddressClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_address_dispose;
+    gobject_class->finalize = gnc_address_finalize;
+    gobject_class->set_property = gnc_address_set_property;
+    gobject_class->get_property = gnc_address_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "Address Name",
+                          "The address name is an arbitrary string "
+                          "assigned by the user.  It is intended to "
+                          "a short string to identify the address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_ADDR1,
+     g_param_spec_string ("addr1",
+                          "Address Line 1",
+                          "The address line 1 is an arbitrary string "
+                          "assigned by the user.  It is the first "
+                          "line of the address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_ADDR2,
+     g_param_spec_string ("addr2",
+                          "Address Line 2",
+                          "The address line 2 is an arbitrary string "
+                          "assigned by the user.  It is the second "
+                          "line of the address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_ADDR3,
+     g_param_spec_string ("addr3",
+                          "Address Line 3",
+                          "The address line 3 is an arbitrary string "
+                          "assigned by the user.  It is the third "
+                          "line of the address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_ADDR4,
+     g_param_spec_string ("addr4",
+                          "Address Line 4",
+                          "The address line 4 is an arbitrary string "
+                          "assigned by the user.  It is the fourth "
+                          "line of the address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_PHONE,
+     g_param_spec_string ("phone",
+                          "Phone",
+                          "The phone number is the number at this address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_FAX,
+     g_param_spec_string ("fax",
+                          "Fax",
+                          "The fax number at this address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_EMAIL,
+     g_param_spec_string ("email",
+                          "E-mail address",
+                          "The e-mail address at this address.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy functions */
+
+GncAddress *
+gncAddressCreate (QofBook *book, QofInstance *prnt)
+{
+    GncAddress *addr;
+
+    if (!book) return NULL;
+
+    addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
+    qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
+    addr->book = book;
+    addr->dirty = FALSE;
+    addr->parent = prnt;
+
+    addr->name = CACHE_INSERT ("");
+    addr->addr1 = CACHE_INSERT ("");
+    addr->addr2 = CACHE_INSERT ("");
+    addr->addr3 = CACHE_INSERT ("");
+    addr->addr4 = CACHE_INSERT ("");
+    addr->phone = CACHE_INSERT ("");
+    addr->fax = CACHE_INSERT ("");
+    addr->email = CACHE_INSERT ("");
+
+    return addr;
+}
+
+static GncAddress *
+qofAddressCreate (QofBook *book)
+{
+    /* The address will get set later by another function */
+    return gncAddressCreate(book, NULL);
+}
+
+static void
+qofAddressSetOwner(GncAddress *addr, QofInstance *ent)
+{
+    if (!addr || !ent)
+    {
+        return;
+    }
+    if (addr->parent == NULL)
+    {
+        addr->parent = ent;
+    }
+}
+
+static QofInstance*
+qofAddressGetOwner(const GncAddress *addr)
+{
+
+    if (!addr)
+    {
+        return NULL;
+    }
+    return addr->parent;
+}
+
+GncAddress *
+gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book)
+{
+    GncAddress *addr;
+
+    if (!book) return NULL;
+
+    addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
+    qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
+    addr->book = book;
+    addr->dirty = TRUE;
+    addr->parent = new_parent;
+
+    addr->name = CACHE_INSERT (from->name);
+    addr->addr1 = CACHE_INSERT (from->addr1);
+    addr->addr2 = CACHE_INSERT (from->addr2);
+    addr->addr3 = CACHE_INSERT (from->addr3);
+    addr->addr4 = CACHE_INSERT (from->addr4);
+    addr->phone = CACHE_INSERT (from->phone);
+    addr->fax = CACHE_INSERT (from->fax);
+    addr->email = CACHE_INSERT (from->email);
+
+    return addr;
+}
+
+void
+gncAddressDestroy (GncAddress *addr)
+{
+    if (!addr) return;
+    qof_instance_set_destroying(addr, TRUE);
+    gncAddressCommitEdit (addr);
+}
+
+static void
+gncAddressFree (GncAddress *addr)
+{
+    if (!addr) return;
+
+    qof_event_gen (&addr->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (addr->name);
+    CACHE_REMOVE (addr->addr1);
+    CACHE_REMOVE (addr->addr2);
+    CACHE_REMOVE (addr->addr3);
+    CACHE_REMOVE (addr->addr4);
+    CACHE_REMOVE (addr->phone);
+    CACHE_REMOVE (addr->fax);
+    CACHE_REMOVE (addr->email);
+
+    /* qof_instance_release (&addr->inst); */
+    g_object_unref (addr);
+}
+
+
+/* Set functions */
+
+#define SET_STR(obj, member, str) { \
+	char * tmp; \
+	\
+	if (member == str) return; \
+	if (!safe_strcmp (member, str)) return; \
+	gncAddressBeginEdit (obj); \
+	tmp = CACHE_INSERT (str); \
+	CACHE_REMOVE (member); \
+	member = tmp; \
+	}
+
+void gncAddressSetName (GncAddress *addr, const char *name)
+{
+    if (!addr) return;
+    if (!name) return;
+    SET_STR(addr, addr->name, name);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetAddr1 (GncAddress *addr, const char *addr1)
+{
+    if (!addr) return;
+    if (!addr1) return;
+    SET_STR(addr, addr->addr1, addr1);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetAddr2 (GncAddress *addr, const char *addr2)
+{
+    if (!addr) return;
+    if (!addr2) return;
+    SET_STR(addr, addr->addr2, addr2);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetAddr3 (GncAddress *addr, const char *addr3)
+{
+    if (!addr) return;
+    if (!addr3) return;
+    SET_STR(addr, addr->addr3, addr3);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetAddr4 (GncAddress *addr, const char *addr4)
+{
+    if (!addr) return;
+    if (!addr4) return;
+    SET_STR(addr, addr->addr4, addr4);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetPhone (GncAddress *addr, const char *phone)
+{
+    if (!addr) return;
+    if (!phone) return;
+    SET_STR(addr, addr->phone, phone);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetFax (GncAddress *addr, const char *fax)
+{
+    if (!addr) return;
+    if (!fax) return;
+    SET_STR(addr, addr->fax, fax);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressSetEmail (GncAddress *addr, const char *email)
+{
+    if (!addr) return;
+    if (!email) return;
+    SET_STR(addr, addr->email, email);
+    mark_address (addr);
+    gncAddressCommitEdit (addr);
+}
+
+void gncAddressBeginEdit (GncAddress *addr)
+{
+    qof_begin_edit (&addr->inst);
+}
+
+static void gncAddressOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("Address QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncAddressOnDone (QofInstance *addr) { }
+
+static void address_free (QofInstance *inst)
+{
+    GncAddress *addr = (GncAddress *) inst;
+    gncAddressFree (addr);
+}
+
+void gncAddressCommitEdit (GncAddress *addr)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(addr))) return;
+    qof_commit_edit_part2 (&addr->inst, gncAddressOnError,
+                           gncAddressOnDone, address_free);
+}
+
+
+/* Get Functions */
+
+const char * gncAddressGetName (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->name;
+}
+
+const char * gncAddressGetAddr1 (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->addr1;
+}
+
+const char * gncAddressGetAddr2 (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->addr2;
+}
+
+const char * gncAddressGetAddr3 (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->addr3;
+}
+
+const char * gncAddressGetAddr4 (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->addr4;
+}
+
+const char * gncAddressGetPhone (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->phone;
+}
+
+const char * gncAddressGetFax (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->fax;
+}
+
+const char * gncAddressGetEmail (const GncAddress *addr)
+{
+    if (!addr) return NULL;
+    return addr->email;
+}
+
+gboolean gncAddressIsDirty (const GncAddress *addr)
+{
+    if (!addr) return FALSE;
+    return addr->dirty;
+}
+
+void gncAddressClearDirty (GncAddress *addr)
+{
+    if (!addr) return;
+    addr->dirty = FALSE;
+}
+
+int gncAddressCompare (const GncAddress *a, const GncAddress *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    return safe_strcmp (a->name, b->name);
+}
+
+gboolean
+gncAddressEqual(const GncAddress* a, const GncAddress* b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
+    g_return_val_if_fail(GNC_IS_ADDRESS(b), FALSE);
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+    if (safe_strcmp(a->addr1, b->addr1) != 0)
+    {
+        PWARN("address lines 1 differ: %s vs %s", a->addr1, b->addr1);
+        return FALSE;
+    }
+    if (safe_strcmp(a->addr2, b->addr2) != 0)
+    {
+        PWARN("address lines 2 differ: %s vs %s", a->addr2, b->addr1);
+        return FALSE;
+    }
+    if (safe_strcmp(a->addr3, b->addr3) != 0)
+    {
+        PWARN("address lines 3 differ: %s vs %s", a->addr3, b->addr3);
+        return FALSE;
+    }
+    if (safe_strcmp(a->addr4, b->addr4) != 0)
+    {
+        PWARN("address lines 4 differ: %s vs %s", a->addr4, b->addr4);
+        return FALSE;
+    }
+    if (safe_strcmp(a->phone, b->phone) != 0)
+    {
+        PWARN("phone numbers differ: %s vs %s", a->phone, b->phone);
+        return FALSE;
+    }
+    if (safe_strcmp(a->fax, b->fax) != 0)
+    {
+        PWARN("fax numbers differ: %s vs %s", a->fax, b->fax);
+        return FALSE;
+    }
+    if (safe_strcmp(a->email, b->email) != 0)
+    {
+        PWARN("email addresses differ: %s vs %s", a->email, b->email);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static QofObject GncAddressDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) GNC_ID_ADDRESS,
+    DI(.type_label        = ) "Address",
+    DI(.create            = ) (gpointer)qofAddressCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) NULL,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncAddressRegister (void)
+{
+    static QofParam params[] =
+    {
+
+        { ADDRESS_NAME,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName,  (QofSetterFunc)gncAddressSetName },
+        { ADDRESS_ONE,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr1, (QofSetterFunc)gncAddressSetAddr1 },
+        { ADDRESS_TWO,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr2, (QofSetterFunc)gncAddressSetAddr2 },
+        { ADDRESS_THREE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr3, (QofSetterFunc)gncAddressSetAddr3 },
+        { ADDRESS_FOUR,  QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetAddr4, (QofSetterFunc)gncAddressSetAddr4 },
+        { ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, (QofSetterFunc)gncAddressSetPhone },
+        { ADDRESS_FAX,   QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax,   (QofSetterFunc)gncAddressSetFax },
+        { ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, (QofSetterFunc)gncAddressSetEmail },
+        { ADDRESS_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofAddressGetOwner, (QofSetterFunc)qofAddressSetOwner },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK,   (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    qof_class_register (GNC_ID_ADDRESS, (QofSortFunc)gncAddressCompare, params);
+    if (!qof_choice_add_class(GNC_ID_CUSTOMER, GNC_ID_ADDRESS, ADDRESS_OWNER))
+    {
+        return FALSE;
+    }
+
+    return qof_object_register(&GncAddressDesc);
+}

Copied: gnucash/trunk/src/engine/gncAddress.h (from rev 19328, gnucash/trunk/src/business/business-core/gncAddress.h)
===================================================================
--- gnucash/trunk/src/engine/gncAddress.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncAddress.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,159 @@
+/********************************************************************\
+ * gncAddress.h -- an Address object                                *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Address
+
+An address belongs to another object, determined by the ::GncOwner.
+It is the owner that assigns a name and identifier to the address.
+In effect, an address is just a building - to make it useful to
+GnuCash, it needs to be tied to a person. After all, you cannot
+invoice a building, you invoice a person working / living in the
+building.
+
+QOF needs to handle all objects generically and to tie the address
+to an owner, QOF must be able to find each - as entities.
+
+This allows QOF to follow the hierarchy of objects without having
+to call any application-specific routines.
+
+To achieve this, new GncAddress routines have been added. An address
+is now created with a NULL parent and the parent set explicitly using
+the QOF object declaration. Whilst this adds functionality, it is
+important that a valid ::GncOwner entity is always set as a parent.
+This is an API issue - QOF will always set the parent provided that
+a suitable entity is passed to the qofAddressSetOwner routine. It is
+up to you to pass a suitable entity.
+
+    @{ */
+/** @file gncAddress.h
+    @brief an Address object
+    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
+    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+*/
+
+#ifndef GNC_ADDRESS_H_
+#define GNC_ADDRESS_H_
+
+#include "qof.h"
+#ifdef GNUCASH_MAJOR_VERSION
+#include "gncBusiness.h"
+#endif
+
+#define GNC_ADDRESS_MODULE_NAME        "gncAddress"
+#define GNC_ID_ADDRESS GNC_ADDRESS_MODULE_NAME
+/** \struct GncAddress
+
+ at param  QofInstance The address instance.
+ at param	QofBook*	  Copy of the book pointer.
+ at param	QofInstance* parent entity.
+ at param	gboolean	dirty flag
+ at param	char*	name of addressee
+ at param	char*	first line of address
+ at param	char*	second line of address
+ at param	char*	third line of address
+ at param	char*	fourth line of address
+ at param	char*	phone number
+ at param	char*	fax number
+ at param	char*	email address
+*/
+typedef struct _gncAddress GncAddress;
+typedef struct _gncAddressClass GncAddressClass;
+
+/* --- type macros --- */
+#define GNC_TYPE_ADDRESS            (gnc_address_get_type ())
+#define GNC_ADDRESS(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ADDRESS, GncAddress))
+#define GNC_ADDRESS_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ADDRESS, GncAddressClass))
+#define GNC_IS_ADDRESS(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ADDRESS))
+#define GNC_IS_ADDRESS_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ADDRESS))
+#define GNC_ADDRESS_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ADDRESS, GncAddressClass))
+GType gnc_address_get_type(void);
+
+/** @name Create/Destroy functions
+ @{ */
+GncAddress *gncAddressCreate (QofBook *book, QofInstance *parent);
+void gncAddressDestroy (GncAddress *addr);
+void gncAddressBeginEdit (GncAddress *addr);
+void gncAddressCommitEdit (GncAddress *addr);
+
+/** @} */
+
+/** @name Set functions
+ @{ */
+
+void gncAddressSetName (GncAddress *addr, const char *name);
+void gncAddressSetAddr1 (GncAddress *addr, const char *addr1);
+void gncAddressSetAddr2 (GncAddress *addr, const char *addr2);
+void gncAddressSetAddr3 (GncAddress *addr, const char *addr3);
+void gncAddressSetAddr4 (GncAddress *addr, const char *addr4);
+void gncAddressSetPhone (GncAddress *addr, const char *phone);
+void gncAddressSetFax (GncAddress *addr, const char *fax);
+void gncAddressSetEmail (GncAddress *addr, const char *email);
+void gncAddressClearDirty (GncAddress *address);
+/** @} */
+
+/** @name Get Functions
+ @{ */
+
+const char * gncAddressGetName (const GncAddress *addr);
+const char * gncAddressGetAddr1 (const GncAddress *addr);
+const char * gncAddressGetAddr2 (const GncAddress *addr);
+const char * gncAddressGetAddr3 (const GncAddress *addr);
+const char * gncAddressGetAddr4 (const GncAddress *addr);
+const char * gncAddressGetPhone (const GncAddress *addr);
+const char * gncAddressGetFax (const GncAddress *addr);
+const char * gncAddressGetEmail (const GncAddress *addr);
+/** @} */
+
+gboolean gncAddressIsDirty (const GncAddress *addr);
+
+/** \brief compare two addresses
+
+\return 0 if identical, -1 if a is empty or less than b
+and +1 if a is more than b or if b is empty.
+*/
+int gncAddressCompare (const GncAddress *a, const GncAddress *b);
+
+/** \brief Deeply compare two addresses
+
+\return TRUE if all fields match, FALSE otherwise
+*/
+gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b);
+
+#define ADDRESS_NAME    "name"
+#define ADDRESS_ONE		"number"
+#define ADDRESS_TWO		"street"
+#define ADDRESS_THREE   "locality"
+#define ADDRESS_FOUR	"city"
+#define ADDRESS_PHONE   "phone"
+#define ADDRESS_FAX     "fax"
+#define ADDRESS_EMAIL   "email"
+#define ADDRESS_OWNER   "owner"
+
+#endif /* GNC_ADDRESS_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncAddressP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncAddressP.h)
===================================================================
--- gnucash/trunk/src/engine/gncAddressP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncAddressP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,39 @@
+/********************************************************************\
+ * gncAddressP.h -- Private Business Interface:  Addresses          *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001, 2002 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_ADDRESSP_H_
+#define GNC_ADDRESSP_H_
+
+#include "gncAddress.h"
+
+gboolean gncAddressRegister (void);
+
+/** Make a copy of the address, setting the parent to 'new_parent' */
+GncAddress * gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book);
+
+
+#endif /* GNC_ADDRESSP_H_ */

Copied: gnucash/trunk/src/engine/gncBillTerm.c (from rev 19328, gnucash/trunk/src/business/business-core/gncBillTerm.c)
===================================================================
--- gnucash/trunk/src/engine/gncBillTerm.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBillTerm.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,941 @@
+/********************************************************************\
+ * gncBillTerm.c -- the Gnucash Billing Terms interface             *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "gnc-engine.h"
+#include "gncBillTermP.h"
+
+struct _gncBillTerm
+{
+    QofInstance     inst;
+
+    /* 'visible' data fields directly manipulated by user */
+    char *          name;
+    char *          desc;
+    GncBillTermType type;
+    gint            due_days;
+    gint            disc_days;
+    gnc_numeric     discount;
+    gint            cutoff;
+
+    /* Internal management fields */
+    /* See src/doc/business.txt for an explanation of the following */
+    /* Code that handles this is *identical* to that in gncTaxTable */
+    gint64          refcount;
+    GncBillTerm *   parent;      /* if non-null, we are an immutable child */
+    GncBillTerm *   child;       /* if non-null, we have not changed */
+    gboolean        invisible;
+    GList *         children;    /* list of children for disconnection */
+};
+
+struct _gncBillTermClass
+{
+    QofInstanceClass parent_class;
+};
+
+struct _book_info
+{
+    GList *         terms;        /* visible terms */
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME        GNC_ID_BILLTERM
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncBillTermBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+AS_STRING_DEC(GncBillTermType, ENUM_TERMS_TYPE)
+FROM_STRING_DEC(GncBillTermType, ENUM_TERMS_TYPE)
+
+/* ============================================================== */
+/* Misc inline utilities */
+
+static inline void
+mark_term (GncBillTerm *term)
+{
+    qof_instance_set_dirty(&term->inst);
+    qof_event_gen (&term->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+static inline void maybe_resort_list (GncBillTerm *term)
+{
+    struct _book_info *bi;
+
+    if (term->parent || term->invisible) return;
+    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
+    bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
+}
+
+static inline void addObj (GncBillTerm *term)
+{
+    struct _book_info *bi;
+    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
+    bi->terms = g_list_insert_sorted (bi->terms, term,
+                                      (GCompareFunc)gncBillTermCompare);
+}
+
+static inline void remObj (GncBillTerm *term)
+{
+    struct _book_info *bi;
+    bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
+    bi->terms = g_list_remove (bi->terms, term);
+}
+
+static inline void
+gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
+{
+    g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
+    table->children = g_list_prepend(table->children, child);
+}
+
+static inline void
+gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
+{
+    if (qof_instance_get_destroying(table)) return;
+    table->children = g_list_remove(table->children, child);
+}
+
+/* ============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncBillTerm, gnc_billterm, QOF_TYPE_INSTANCE);
+
+static void
+gnc_billterm_init(GncBillTerm* bt)
+{
+}
+
+static void
+gnc_billterm_dispose(GObject *btp)
+{
+    G_OBJECT_CLASS(gnc_billterm_parent_class)->dispose(btp);
+}
+
+static void
+gnc_billterm_finalize(GObject* btp)
+{
+    G_OBJECT_CLASS(gnc_billterm_parent_class)->finalize(btp);
+}
+
+static void
+gnc_billterm_get_property (GObject         *object,
+                           guint            prop_id,
+                           GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncBillTerm *bt;
+
+    g_return_if_fail(GNC_IS_BILLTERM(object));
+
+    bt = GNC_BILLTERM(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, bt->name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_billterm_set_property (GObject         *object,
+                           guint            prop_id,
+                           const GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncBillTerm *bt;
+
+    g_return_if_fail(GNC_IS_BILLTERM(object));
+
+    bt = GNC_BILLTERM(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncBillTermSetName(bt, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Bill term doesn't refer to anything except other billterms */
+    return NULL;
+}
+
+static void
+gnc_billterm_class_init (GncBillTermClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_billterm_dispose;
+    gobject_class->finalize = gnc_billterm_finalize;
+    gobject_class->set_property = gnc_billterm_set_property;
+    gobject_class->get_property = gnc_billterm_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "BillTerm Name",
+                          "The bill term name is an arbitrary string "
+                          "assigned by the user.  It is intended to "
+                          "a short, 10 to 30 character long string "
+                          "that is displayed by the GUI as the "
+                          "billterm mnemonic.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncBillTerm * gncBillTermCreate (QofBook *book)
+{
+    GncBillTerm *term;
+    if (!book) return NULL;
+
+    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
+    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
+    term->name = CACHE_INSERT ("");
+    term->desc = CACHE_INSERT ("");
+    term->discount = gnc_numeric_zero ();
+    addObj (term);
+    qof_event_gen (&term->inst,  QOF_EVENT_CREATE, NULL);
+    return term;
+}
+
+void gncBillTermDestroy (GncBillTerm *term)
+{
+    if (!term) return;
+    DEBUG("destroying bill term %s (%p)",
+          guid_to_string(qof_instance_get_guid(&term->inst)), term);
+    qof_instance_set_destroying(term, TRUE);
+    qof_instance_set_dirty (&term->inst);
+    gncBillTermCommitEdit (term);
+}
+
+static void gncBillTermFree (GncBillTerm *term)
+{
+    GncBillTerm *child;
+    GList *list;
+
+    if (!term) return;
+
+    qof_event_gen (&term->inst,  QOF_EVENT_DESTROY, NULL);
+    CACHE_REMOVE (term->name);
+    CACHE_REMOVE (term->desc);
+    remObj (term);
+
+    if (!qof_instance_get_destroying(term))
+        PERR("free a billterm without do_free set!");
+
+    /* disconnect from parent */
+    if (term->parent)
+        gncBillTermRemoveChild(term->parent, term);
+
+    /* disconnect from the children */
+    for (list = term->children; list; list = list->next)
+    {
+        child = list->data;
+        gncBillTermSetParent(child, NULL);
+    }
+    g_list_free(term->children);
+
+    /* qof_instance_release(&term->inst); */
+    g_object_unref (term);
+}
+
+GncBillTerm *
+gncCloneBillTerm (GncBillTerm *from, QofBook *book)
+{
+    GList *node;
+    GncBillTerm *term;
+
+    if (!book || !from) return NULL;
+
+    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
+    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&term->inst, &from->inst);
+
+    term->name = CACHE_INSERT (from->name);
+    term->desc = CACHE_INSERT (from->desc);
+    term->type = from->type;
+    term->due_days = from->due_days;
+    term->disc_days = from->disc_days;
+    term->discount = from->discount;
+    term->cutoff = from->cutoff;
+    term->invisible = from->invisible;
+
+    term->refcount = 0;
+
+    /* Make copies of parents and children. Note that this can be
+     * a recursive copy ... treat as doubly-linked list. */
+    if (from->child)
+    {
+        term->child = gncBillTermObtainTwin (from->child, book);
+        term->child->parent = term;
+    }
+    if (from->parent)
+    {
+        term->parent = gncBillTermObtainTwin (from->parent, book);
+        term->parent->child = term;
+    }
+    for (node = g_list_last(from->children); node; node = node->next)
+    {
+        GncBillTerm *btrm = node->data;
+        btrm = gncBillTermObtainTwin (btrm, book);
+        btrm->parent = term;
+        term->children = g_list_prepend(term->children, btrm);
+    }
+
+    addObj (term);
+    qof_event_gen (&term->inst, QOF_EVENT_CREATE, NULL);
+    return term;
+}
+
+GncBillTerm *
+gncBillTermObtainTwin (GncBillTerm *from, QofBook *book)
+{
+    GncBillTerm *term;
+    if (!from) return NULL;
+
+    term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!term)
+    {
+        term = gncCloneBillTerm (from, book);
+    }
+    return term;
+}
+
+/* ============================================================== */
+/* Set Functions */
+
+void gncBillTermSetName (GncBillTerm *term, const char *name)
+{
+    if (!term || !name) return;
+    SET_STR (term, term->name, name);
+    mark_term (term);
+    maybe_resort_list (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetDescription (GncBillTerm *term, const char *desc)
+{
+    if (!term || !desc) return;
+    SET_STR (term, term->desc, desc);
+    mark_term (term);
+    maybe_resort_list (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetType (GncBillTerm *term, GncBillTermType type)
+{
+    if (!term) return;
+    if (term->type == type) return;
+    gncBillTermBeginEdit (term);
+    term->type = type;
+    mark_term (term);
+    gncBillTermCommitEdit (term);
+}
+
+/** \brief Convert bill term types from text. */
+FROM_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
+
+static
+void qofBillTermSetType (GncBillTerm *term, const char *type_label)
+{
+    GncBillTermType type;
+
+    type = GncBillTermTypefromString(type_label);
+    gncBillTermSetType(term, type);
+}
+
+void gncBillTermSetDueDays (GncBillTerm *term, gint days)
+{
+    if (!term) return;
+    if (term->due_days == days) return;
+    gncBillTermBeginEdit (term);
+    term->due_days = days;
+    mark_term (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetDiscountDays (GncBillTerm *term, gint days)
+{
+    if (!term) return;
+    if (term->disc_days == days) return;
+    gncBillTermBeginEdit (term);
+    term->disc_days = days;
+    mark_term (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetDiscount (GncBillTerm *term, gnc_numeric discount)
+{
+    if (!term) return;
+    if (gnc_numeric_eq (term->discount, discount)) return;
+    gncBillTermBeginEdit (term);
+    term->discount = discount;
+    mark_term (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff)
+{
+    if (!term) return;
+    if (term->cutoff == cutoff) return;
+    gncBillTermBeginEdit (term);
+    term->cutoff = cutoff;
+    mark_term (term);
+    gncBillTermCommitEdit (term);
+}
+
+/* XXX this doesn't seem right. If the parent/child relationship
+ * is a doubly-linked list, then there shouldn't be separate set-parent,
+ * set-child routines, else misuse of the routines will goof up
+ * relationships.  These ops should be atomic, I think.
+ */
+void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent)
+{
+    if (!term) return;
+    gncBillTermBeginEdit (term);
+    if (term->parent)
+        gncBillTermRemoveChild(term->parent, term);
+    term->parent = parent;
+    if (parent)
+        gncBillTermAddChild(parent, term);
+    term->refcount = 0;
+    if ( parent != NULL )
+    {
+        gncBillTermMakeInvisible (term);
+    }
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child)
+{
+    if (!term) return;
+    gncBillTermBeginEdit (term);
+    term->child = child;
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermIncRef (GncBillTerm *term)
+{
+    if (!term) return;
+    if (term->parent || term->invisible) return;        /* children dont need refcounts */
+    gncBillTermBeginEdit (term);
+    term->refcount++;
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermDecRef (GncBillTerm *term)
+{
+    if (!term) return;
+    if (term->parent || term->invisible) return;        /* children dont need refcounts */
+    gncBillTermBeginEdit (term);
+    term->refcount--;
+    g_return_if_fail (term->refcount >= 0);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount)
+{
+    if (!term) return;
+    term->refcount = refcount;
+}
+
+void gncBillTermMakeInvisible (GncBillTerm *term)
+{
+    if (!term) return;
+    gncBillTermBeginEdit (term);
+    term->invisible = TRUE;
+    remObj (term);
+    gncBillTermCommitEdit (term);
+}
+
+void gncBillTermChanged (GncBillTerm *term)
+{
+    if (!term) return;
+    term->child = NULL;
+}
+
+void gncBillTermBeginEdit (GncBillTerm *term)
+{
+    qof_begin_edit(&term->inst);
+}
+
+static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("BillTerm QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void bill_free (QofInstance *inst)
+{
+    GncBillTerm *term = (GncBillTerm *) inst;
+    gncBillTermFree(term);
+}
+
+static void on_done (QofInstance *inst) {}
+
+void gncBillTermCommitEdit (GncBillTerm *term)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(term))) return;
+    qof_commit_edit_part2 (&term->inst, gncBillTermOnError,
+                           on_done, bill_free);
+}
+
+/* Get Functions */
+
+GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name)
+{
+    GList *list = gncBillTermGetTerms (book);
+
+    for ( ; list; list = list->next)
+    {
+        GncBillTerm *term = list->data;
+        if (!safe_strcmp (term->name, name))
+            return list->data;
+    }
+    return NULL;
+}
+
+GList * gncBillTermGetTerms (QofBook *book)
+{
+    struct _book_info *bi;
+    if (!book) return NULL;
+
+    bi = qof_book_get_data (book, _GNC_MOD_NAME);
+    return bi->terms;
+}
+
+const char *gncBillTermGetName (const GncBillTerm *term)
+{
+    if (!term) return NULL;
+    return term->name;
+}
+
+const char *gncBillTermGetDescription (const GncBillTerm *term)
+{
+    if (!term) return NULL;
+    return term->desc;
+}
+
+GncBillTermType gncBillTermGetType (const GncBillTerm *term)
+{
+    if (!term) return 0;
+    return term->type;
+}
+
+/** \brief Convert bill term types to text. */
+AS_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
+
+static
+const char* qofBillTermGetType (const GncBillTerm *term)
+{
+    if (!term)
+    {
+        return NULL;
+    }
+    return GncBillTermTypeasString(term->type);
+}
+
+gint gncBillTermGetDueDays (const GncBillTerm *term)
+{
+    if (!term) return 0;
+    return term->due_days;
+}
+
+gint gncBillTermGetDiscountDays (const GncBillTerm *term)
+{
+    if (!term) return 0;
+    return term->disc_days;
+}
+
+gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term)
+{
+    if (!term) return gnc_numeric_zero ();
+    return term->discount;
+}
+
+gint gncBillTermGetCutoff (const GncBillTerm *term)
+{
+    if (!term) return 0;
+    return term->cutoff;
+}
+
+static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
+{
+    GncBillTerm *t;
+
+    if (!term) return NULL;
+    t = gncBillTermCreate (qof_instance_get_book(term));
+
+    gncBillTermBeginEdit(t);
+
+    gncBillTermSetName (t, term->name);
+    gncBillTermSetDescription (t, term->desc);
+
+    t->type = term->type;
+    t->due_days = term->due_days;
+    t->disc_days = term->disc_days;
+    t->discount = term->discount;
+    t->cutoff = term->cutoff;
+
+    gncBillTermCommitEdit(t);
+
+    return t;
+}
+
+GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new)
+{
+    GncBillTerm *child = NULL;
+
+    if (!term) return NULL;
+    if (term->child) return term->child;
+    if (term->parent || term->invisible) return term;
+    if (make_new)
+    {
+        child = gncBillTermCopy (term);
+        gncBillTermSetChild (term, child);
+        gncBillTermSetParent (child, term);
+    }
+    return child;
+}
+
+GncBillTerm *gncBillTermGetParent (const GncBillTerm *term)
+{
+    if (!term) return NULL;
+    return term->parent;
+}
+
+gint64 gncBillTermGetRefcount (const GncBillTerm *term)
+{
+    if (!term) return 0;
+    return term->refcount;
+}
+
+gboolean gncBillTermGetInvisible (const GncBillTerm *term)
+{
+    if (!term) return FALSE;
+    return term->invisible;
+}
+
+int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b)
+{
+    int ret;
+
+    if (!a && !b) return 0;
+    if (!a) return -1;
+    if (!b) return 1;
+
+    ret = safe_strcmp (a->name, b->name);
+    if (ret) return ret;
+
+    return safe_strcmp (a->desc, b->desc);
+}
+
+gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_BILLTERM(a), FALSE);
+    g_return_val_if_fail(GNC_IS_BILLTERM(b), FALSE);
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("Names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->desc, b->desc) != 0)
+    {
+        PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
+        return FALSE;
+    }
+
+    if (a->type != b->type)
+    {
+        PWARN("Types differ");
+        return FALSE;
+    }
+
+    if (a->due_days != b->due_days)
+    {
+        PWARN("Due days differ: %d vs %d", a->due_days, b->due_days);
+        return FALSE;
+    }
+
+    if (a->disc_days != b->disc_days)
+    {
+        PWARN("Discount days differ: %d vs %d", a->disc_days, b->disc_days);
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->discount, b->discount))
+    {
+        PWARN("Discounts differ");
+        return FALSE;
+    }
+
+    if (a->cutoff != b->cutoff)
+    {
+        PWARN("Cutoffs differ: %d vs %d", a->cutoff, b->cutoff);
+        return FALSE;
+    }
+
+    if (a->invisible != b->invisible)
+    {
+        PWARN("Invisible flags differ");
+        return FALSE;
+    }
+
+//    gint64          refcount;
+//    GncBillTerm *   parent;      /* if non-null, we are an immutable child */
+//    GncBillTerm *   child;       /* if non-null, we have not changed */
+//    GList *         children;    /* list of children for disconnection */
+
+    return TRUE;
+}
+
+gboolean gncBillTermIsDirty (const GncBillTerm *term)
+{
+    if (!term) return FALSE;
+    return qof_instance_get_dirty_flag(term);
+}
+
+/********************************************************/
+/* functions to compute dates from Bill Terms           */
+
+#define SECS_PER_DAY 86400
+
+/* Based on the post date and a proximo type, compute the month and
+ * year this is due.  The actual day is filled in below.
+ *
+ * A proximo billing term has multiple parameters:
+ * * due day: day of the month the invoice/bill will be due
+ * * cutoff: day of the month used to decide if the due date will be
+ *           in the next month or in the month thereafter. This can be
+ *           a negative number in which case the cutoff date is relative
+ *           to the end of the month and counting backwards.
+ *           Eg: cutoff = -3 would mean 25 in February or 28 in June
+ *
+ * How does it work:
+ * Assume cutoff = 19 and due day = 20
+ *
+ * * Example 1 post date = 14-06-2010 (European date format)
+ *   14 is less than the cutoff of 19, so the due date will be in the next
+ *   month. Since the due day is set to 20, the due date will be
+ *   20-07-2010
+ *
+ * * Example 2 post date = 22-06-2010 (European date format)
+ *   22 is more than the cutoff of 19, so the due date will be in the month
+ *   after next month. Since the due day is set to 20, the due date will be
+ *   20-02-2010
+ *
+ */
+static void
+compute_monthyear (const GncBillTerm *term, Timespec post_date,
+                   int *month, int *year)
+{
+    int iday, imonth, iyear;
+    int cutoff = term->cutoff;
+
+    g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
+
+    gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
+
+    if (cutoff <= 0)
+        cutoff += gnc_timespec_last_mday (post_date);
+
+    if (iday <= cutoff)
+    {
+        /* We apply this to next month */
+        imonth++;
+    }
+    else
+    {
+        /* We apply to the following month */
+        imonth += 2;
+    }
+
+    if (imonth > 12)
+    {
+        iyear++;
+        imonth -= 12;
+    }
+
+    if (month) *month = imonth;
+    if (year) *year = iyear;
+}
+
+/* There are two types of billing terms:
+ *
+ * Type DAYS defines a due date to be a fixed number of days passed the post
+ * date. This is a straightforward calculation.
+ *
+ * The other type PROXIMO defines the due date as a fixed day of the month
+ * (like always the 15th of the month). The proximo algorithm determines which
+ * month based on the cutoff day and the post date. See above for a more
+ * detailed explanation of proximo.
+ */
+
+static Timespec
+compute_time (const GncBillTerm *term, Timespec post_date, int days)
+{
+    Timespec res = post_date;
+    int day, month, year;
+
+    switch (term->type)
+    {
+    case GNC_TERM_TYPE_DAYS:
+        res.tv_sec += (SECS_PER_DAY * days);
+        break;
+    case GNC_TERM_TYPE_PROXIMO:
+        compute_monthyear (term, post_date, &month, &year);
+        day = gnc_date_my_last_mday (month, year);
+        if (days < day)
+            day = days;
+        res = gnc_dmy2timespec (day, month, year);
+        break;
+    }
+    return res;
+}
+
+Timespec
+gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date)
+{
+    Timespec res = post_date;
+    if (!term) return res;
+
+    return compute_time (term, post_date, term->due_days);
+}
+
+Timespec
+gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date)
+{
+    Timespec res = post_date;
+    if (!term) return res;
+
+    return compute_time (term, post_date, term->disc_days);
+}
+
+/* Package-Private functions */
+
+static void _gncBillTermCreate (QofBook *book)
+{
+    struct _book_info *bi;
+
+    if (!book) return;
+
+    bi = g_new0 (struct _book_info, 1);
+    qof_book_set_data (book, _GNC_MOD_NAME, bi);
+}
+
+static void _gncBillTermDestroy (QofBook *book)
+{
+    struct _book_info *bi;
+
+    if (!book) return;
+
+    bi = qof_book_get_data (book, _GNC_MOD_NAME);
+
+    g_list_free (bi->terms);
+    g_free (bi);
+}
+
+static QofObject gncBillTermDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Billing Term",
+    DI(.create            = ) (gpointer)gncBillTermCreate,
+    DI(.book_begin        = ) _gncBillTermCreate,
+    DI(.book_end          = ) _gncBillTermDestroy,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) NULL,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncBillTermRegister (void)
+{
+    static QofParam params[] =
+    {
+        { GNC_BILLTERM_NAME, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetName,			(QofSetterFunc)gncBillTermSetName },
+        { GNC_BILLTERM_DESC, 		QOF_TYPE_STRING,  (QofAccessFunc)gncBillTermGetDescription,		(QofSetterFunc)gncBillTermSetDescription },
+        { GNC_BILLTERM_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofBillTermGetType, (QofSetterFunc)qofBillTermSetType },
+        { GNC_BILLTERM_DUEDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDueDays, 		(QofSetterFunc)gncBillTermSetDueDays },
+        { GNC_BILLTERM_DISCDAYS, 	QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetDiscountDays,	(QofSetterFunc)gncBillTermSetDiscountDays },
+        { GNC_BILLTERM_DISCOUNT, 	QOF_TYPE_NUMERIC, (QofAccessFunc)gncBillTermGetDiscount,		(QofSetterFunc)gncBillTermSetDiscount },
+        { GNC_BILLTERM_CUTOFF, 		QOF_TYPE_INT32,   (QofAccessFunc)gncBillTermGetCutoff, 			(QofSetterFunc)gncBillTermSetCutoff },
+        { GNC_BILLTERM_REFCOUNT, 	QOF_TYPE_INT64,   (QofAccessFunc)gncBillTermGetRefcount, 		NULL },
+        { QOF_PARAM_BOOK, 			QOF_ID_BOOK, 	  (QofAccessFunc)qof_instance_get_book, 		NULL },
+        { QOF_PARAM_GUID, 			QOF_TYPE_GUID, 	  (QofAccessFunc)qof_instance_get_guid, 		NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);
+
+    return qof_object_register (&gncBillTermDesc);
+}

Copied: gnucash/trunk/src/engine/gncBillTerm.h (from rev 19328, gnucash/trunk/src/business/business-core/gncBillTerm.h)
===================================================================
--- gnucash/trunk/src/engine/gncBillTerm.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBillTerm.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,161 @@
+/********************************************************************\
+ * gncBillTerm.h -- the Gnucash Billing Term interface              *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup BillTerm
+    @{ */
+/** @file gncBillTerm.h
+    @brief Billing Term interface
+    @author Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_BILLTERM_H_
+#define GNC_BILLTERM_H_
+
+typedef struct _gncBillTerm GncBillTerm;
+typedef struct _gncBillTermClass GncBillTermClass;
+
+#include "qof.h"
+#ifdef GNUCASH_MAJOR_VERSION
+#include "gncBusiness.h"
+#endif
+#define GNC_ID_BILLTERM       "gncBillTerm"
+
+/* --- type macros --- */
+#define GNC_TYPE_BILLTERM            (gnc_billterm_get_type ())
+#define GNC_BILLTERM(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_BILLTERM, GncBillTerm))
+#define GNC_BILLTERM_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_BILLTERM, GncBillTermClass))
+#define GNC_IS_BILLTERM(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_BILLTERM))
+#define GNC_IS_BILLTERM_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_BILLTERM))
+#define GNC_BILLTERM_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_BILLTERM, GncBillTermClass))
+GType gnc_billterm_get_type(void);
+
+/** @name BillTerm parameter names
+ @{ */
+#define GNC_BILLTERM_NAME 		"name"
+#define GNC_BILLTERM_DESC 		"description"
+#define GNC_BILLTERM_DUEDAYS 	"number of days due"
+#define GNC_BILLTERM_DISCDAYS 	"number of discounted days"
+#define GNC_BILLTERM_CUTOFF 	"cut off"
+#define GNC_BILLTERM_TYPE 		"bill type"
+#define GNC_BILLTERM_DISCOUNT	"amount of discount"
+#define GNC_BILLTERM_REFCOUNT	"reference count"
+/** @} */
+
+/**
+ * How to interpret the amount.
+ * You can interpret it as a VALUE or a PERCENT.
+ * ??? huh?
+ * NOTE: This enum /depends/ on starting at value 1
+ */
+#ifndef SWIG
+#define ENUM_TERMS_TYPE(_)  \
+ _(GNC_TERM_TYPE_DAYS,=1) \
+ _(GNC_TERM_TYPE_PROXIMO,)
+
+DEFINE_ENUM(GncBillTermType, ENUM_TERMS_TYPE)
+#else
+typedef enum
+{
+    GNC_TERM_TYPE_DAYS = 1,
+    GNC_TERM_TYPE_PROXIMO,
+} GncBillTermType;
+#endif
+
+/** @name Create/Destroy Functions
+ @{ */
+GncBillTerm * gncBillTermCreate (QofBook *book);
+void gncBillTermDestroy (GncBillTerm *term);
+void gncBillTermIncRef (GncBillTerm *term);
+void gncBillTermDecRef (GncBillTerm *term);
+
+void gncBillTermChanged (GncBillTerm *term);
+void gncBillTermBeginEdit (GncBillTerm *term);
+void gncBillTermCommitEdit (GncBillTerm *term);
+/** @} */
+
+/** @name Set Functions
+@{
+*/
+void gncBillTermSetName (GncBillTerm *term, const char *name);
+void gncBillTermSetDescription (GncBillTerm *term, const char *name);
+void gncBillTermSetType (GncBillTerm *term, GncBillTermType type);
+void gncBillTermSetDueDays (GncBillTerm *term, gint days);
+void gncBillTermSetDiscountDays (GncBillTerm *term, gint days);
+void gncBillTermSetDiscount (GncBillTerm *term, gnc_numeric discount);
+void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff);
+
+/** @} */
+
+/** @name Get Functions
+ @{ */
+/** Return a pointer to the instance gncBillTerm that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncBillTerm * gncBillTermLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncBillTerm * gncBillTermLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_BILLTERM, GncBillTerm);
+}
+
+GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name);
+GList * gncBillTermGetTerms (QofBook *book);
+
+const char *gncBillTermGetName (const GncBillTerm *term);
+const char *gncBillTermGetDescription (const GncBillTerm *term);
+GncBillTermType gncBillTermGetType (const GncBillTerm *term);
+gint gncBillTermGetDueDays (const GncBillTerm *term);
+gint gncBillTermGetDiscountDays (const GncBillTerm *term);
+gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term);
+gint gncBillTermGetCutoff (const GncBillTerm *term);
+
+gboolean gncBillTermIsDirty (const GncBillTerm *term);
+
+GncBillTerm *gncBillTermGetParent (const GncBillTerm *term);
+GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new);
+#define gncBillTermGetChild(t) gncBillTermReturnChild((t),FALSE)
+gint64 gncBillTermGetRefcount (const GncBillTerm *term);
+/** @} */
+
+int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b);
+gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b);
+
+/********************************************************/
+/* functions to compute dates from Bill Terms           */
+
+/* Compute the due date and discount dates from the post date */
+Timespec gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date);
+Timespec gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date);
+
+/* deprecated */
+#define gncBillTermGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x))
+
+#endif /* GNC_BILLTERM_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncBillTermP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncBillTermP.h)
===================================================================
--- gnucash/trunk/src/engine/gncBillTermP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBillTermP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,70 @@
+/********************************************************************\
+ * gncBillTermP.h -- the Gnucash Billing Term private interface     *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_BILLTERMP_H_
+#define GNC_BILLTERMP_H_
+
+#include "gncBillTerm.h"
+
+gboolean gncBillTermRegister (void);
+
+void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent);
+void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child);
+void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount);
+void gncBillTermMakeInvisible (GncBillTerm *term);
+
+gboolean gncBillTermGetInvisible (const GncBillTerm *term);
+
+/** The gncCloneBillTerm() routine makes a copy of the indicated
+ *  bill term, placing it in the indicated book.  It copies
+ *  the name, description, type, due-days, discount, etc.
+ *  It also copies (as needed) both parents and children, so that
+ *  the parent-child relationship is correctly mirrored in the
+ *  clone.
+ * XXX the refcount is mis-handled. This needs fixin....
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *);
+
+/** The gncBillTermObtainTwin() will find the 'twin' of the
+ *  indicated bill term in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneBillTerm()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book);
+
+#define gncBillTermSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+
+#endif /* GNC_BILLTERMP_H_ */

Copied: gnucash/trunk/src/engine/gncBusGuile.c (from rev 19328, gnucash/trunk/src/business/business-core/gncBusGuile.c)
===================================================================
--- gnucash/trunk/src/engine/gncBusGuile.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusGuile.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,92 @@
+/*
+ * gncBusGuile.c -- Business Guile Helper Functions
+ * Copyright (C) 2003 Derek Atkins
+ * Author: Derek Atkins <warlord at 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
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#include "config.h"
+
+#include "gncBusGuile.h"
+#include "engine-helpers.h"
+#include "swig-runtime.h"
+#include "guile-mappings.h"
+#define FUNC_NAME G_STRFUNC
+
+static swig_type_info *
+get_acct_type ()
+{
+    static swig_type_info * account_type = NULL;
+
+    if (!account_type)
+        account_type = SWIG_TypeQuery("_p_Account");
+
+    return account_type;
+}
+
+int gnc_account_value_pointer_p (SCM arg)
+{
+    swig_type_info * account_type = get_acct_type();
+
+    return (scm_is_pair (arg) &&
+            SWIG_IsPointerOfType(SCM_CAR (arg), account_type) &&
+            gnc_numeric_p (SCM_CDR (arg)));
+}
+
+GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg)
+{
+    GncAccountValue *res;
+    Account *acc = NULL;
+    gnc_numeric value;
+    swig_type_info * account_type = get_acct_type();
+    SCM val;
+
+    /* Get the account */
+    val = SCM_CAR (valuearg);
+    if (!SWIG_IsPointerOfType (val, account_type))
+        return NULL;
+
+    acc = SWIG_MustGetPtr(val, account_type, 1, 0);
+
+    /* Get the value */
+    val = SCM_CDR (valuearg);
+    value = gnc_scm_to_numeric (val);
+
+    /* Build and return the object */
+    res = g_new0 (GncAccountValue, 1);
+    res->account = acc;
+    res->value = value;
+    return res;
+}
+
+SCM gnc_account_value_ptr_to_scm (GncAccountValue *av)
+{
+    swig_type_info * account_type = get_acct_type();
+    gnc_commodity * com;
+    gnc_numeric val;
+
+    if (!av) return SCM_BOOL_F;
+
+    com = xaccAccountGetCommodity (av->account);
+    val = gnc_numeric_convert (av->value, gnc_commodity_get_fraction (com),
+                               GNC_RND_ROUND);
+
+    return scm_cons (SWIG_NewPointerObj(av->account, account_type, 0),
+                     gnc_numeric_to_scm (val));
+}

Copied: gnucash/trunk/src/engine/gncBusGuile.h (from rev 19328, gnucash/trunk/src/business/business-core/gncBusGuile.h)
===================================================================
--- gnucash/trunk/src/engine/gncBusGuile.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusGuile.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,34 @@
+/*
+ * gncBusGuile.h -- Business Guile Helper Functions
+ * Copyright (C) 2003 Derek Atkins
+ * Author: Derek Atkins <warlord at 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
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#ifndef GNC_BUSINESS_GUILE_H_
+#define GNC_BUSINESS_GUILE_H_
+
+#include <gncTaxTable.h>	/* for GncAccountValue */
+#include <libguile.h>
+
+int gnc_account_value_pointer_p (SCM arg);
+GncAccountValue * gnc_scm_to_account_value_ptr (SCM valuearg);
+SCM gnc_account_value_ptr_to_scm (GncAccountValue *);
+
+#endif /* GNC_BUSINESS_GUILE_H_ */

Copied: gnucash/trunk/src/engine/gncBusPeriod.c (from rev 19328, gnucash/trunk/src/business/business-core/gncBusPeriod.c)
===================================================================
--- gnucash/trunk/src/engine/gncBusPeriod.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusPeriod.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,81 @@
+
+/*
+XXX TODO:
+-- contemplate a per-collection (per type) edit/commmit-edit,
+   clone, dirty, etc. functions some more ...
+
+-- turn clone into a generic object callback, so that
+   the ObtainTwin could be qof_instance_obtain_twin,
+   a generic function. (right now its copied everywhere)
+
+-- contemplate copy-on-write, and the true need for cloning,
+   and how to avoid excess cloning for the SQL backend.
+
+-- billterm and taxtables are incompletely cloned, not sure
+   what to do with refcount, ask warlord, need to explore.
+
+-- The following business objects have an id/name/desc/active
+   this could be abstracted into an common object.
+   vendor (customer)
+   bill term (but bill terms doesn't have id or active)
+   job
+
+-- gncVendor should be a base class to gncCustomer (they're
+   identical, but customer adds more stuff).
+
+   Employee could be base class for vendor, its got some of the
+   things (name, addr, active, currency)
+
+-- TaxTable and BillTerm have common parent/child code.
+   this could be abstracted into common code.
+
+=======
+-- finish clone of invoice, entry,
+
+
+-- jobs in the vendor job list that are no longer active should
+   be kept back in old book, removed from new book??
+   ditto jobs in the customer list ??
+
+-- closed orders can be removed from new book ?
+*/
+
+
+
+#include "gncBusiness.h"
+
+/** Copy all customers from one book to another.  Do this
+ *  by iterating over all existing customers in the src book,
+ *  and creating a clone for the dest book. */
+
+void
+gncCustomerCopyAll (QofBook *dest_book, QofBook *src_book)
+{
+
+}
+
+static void
+bill_term_copy_helper (gpointer object, gpointer user_data)
+{
+    QofBook *dest_book = user_data;
+    gncBillTerm *src_term = object;
+    gncCloneBillTerm (src_term, dest_book);
+}
+
+void
+gncBillTermCopyAll (QofBook *dest_book, QofBook *src_book)
+{
+    qof_object_foreach (GNC_BILLTERM_MODULE_NAME,
+                        src_book, bill_term_copy_helper, dest_book);
+}
+
+
+
+partition (QofBook *dest_book, QofBook *src_book)
+{
+
+    /* Copy all bill terms first, since the CustomerCopy expects
+     * these to be in place already. */
+    /* XXX not strictly needed, the customer can pull their own .. ? */
+    gncBillTermCopyAll (dest_book, src_book);
+}

Copied: gnucash/trunk/src/engine/gncBusiness.c (from rev 19328, gnucash/trunk/src/business/business-core/gncBusiness.c)
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusiness.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,57 @@
+/*
+ * gncBusiness.c -- Business helper functions
+ * Copyright (C) 2002 Derek Atkins
+ * Author: Derek Atkins <warlord at 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
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#include "config.h"
+
+#include "gncBusiness.h"
+
+#include <glib.h>
+
+#include "gncAddressP.h"
+#include "gncBillTermP.h"
+#include "gncCustomerP.h"
+#include "gncEmployeeP.h"
+#include "gncEntryP.h"
+#include "gncInvoiceP.h"
+#include "gncJobP.h"
+#include "gncOrderP.h"
+#include "gncOwnerP.h"
+#include "gncTaxTableP.h"
+#include "gncVendorP.h"
+
+void
+gnc_module_init_business_core_init(void)
+{
+    /* initialize known types */
+    gncInvoiceRegister ();
+    gncJobRegister ();
+    gncBillTermRegister ();
+    gncCustomerRegister ();
+    gncAddressRegister ();
+    gncEmployeeRegister ();
+    gncEntryRegister ();
+    gncOrderRegister ();
+    gncOwnerRegister ();
+    gncTaxTableRegister ();
+    gncVendorRegister ();
+}

Copied: gnucash/trunk/src/engine/gncBusiness.h (from rev 19328, gnucash/trunk/src/business/business-core/gncBusiness.h)
===================================================================
--- gnucash/trunk/src/engine/gncBusiness.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncBusiness.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,63 @@
+/* gncBusiness.h -- Business Helper Functions
+ *
+ * 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
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+/** @addtogroup Engine
+    @{ */
+/** @addtogroup Business
+    The Business Engine provides a set of structures for
+    that provide small-business accounting features.
+    @{ */
+
+/** @file gncBusiness.h -- Business Helper Functions
+ *  @author Copyright (C) 2002 Derek Atkins
+ *  @author Derek Atkins <warlord at MIT.EDU>
+ */
+
+/** @} */
+/** @} */
+#ifndef GNC_BUSINESS_H_
+#define GNC_BUSINESS_H_
+
+
+/* @deprecated backwards-compat definitions */
+#define GNC_BILLTERM_MODULE_NAME GNC_ID_BILLTERM
+#define GNC_CUSTOMER_MODULE_NAME GNC_ID_CUSTOMER
+#define GNC_EMPLOYEE_MODULE_NAME GNC_ID_EMPLOYEE
+#define GNC_ENTRY_MODULE_NAME    GNC_ID_ENTRY
+#define GNC_INVOICE_MODULE_NAME  GNC_ID_INVOICE
+#define GNC_JOB_MODULE_NAME      GNC_ID_JOB
+#define GNC_ORDER_MODULE_NAME    GNC_ID_ORDER
+#define GNC_OWNER_MODULE_NAME    GNC_ID_OWNER
+#define GNC_TAXTABLE_MODULE_NAME GNC_ID_TAXTABLE
+#define GNC_VENDOR_MODULE_NAME   GNC_ID_VENDOR
+
+void
+gnc_module_init_business_core_init(void);
+
+#ifndef DI
+# ifdef _MSC_VER
+/* MSVC compiler doesn't have C99 "designated initializers"
+ * so we wrap them in a macro that is empty on MSVC. */
+#  define DI(x) /* */
+# else
+#  define DI(x) x
+# endif
+#endif
+
+#endif /* GNC_BUSINESS_H_ */

Copied: gnucash/trunk/src/engine/gncCustomer.c (from rev 19328, gnucash/trunk/src/business/business-core/gncCustomer.c)
===================================================================
--- gnucash/trunk/src/engine/gncCustomer.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncCustomer.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,933 @@
+/********************************************************************\
+ * gncCustomer.c -- the Core Customer Interface                     *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001,2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>
+
+#include "gnc-commodity.h"
+
+#include "gncAddressP.h"
+#include "gncBillTermP.h"
+#include "gncInvoice.h"
+#ifdef GNUCASH_MAJOR_VERSION
+#include "gncBusiness.h"
+#endif
+
+#include "gncCustomer.h"
+#include "gncCustomerP.h"
+#include "gncJobP.h"
+#include "gncTaxTableP.h"
+
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                                      gpointer user_data, gpointer event_data);
+
+struct _gncCustomer
+{
+    QofInstance     inst;
+
+    /* The following fields are identical to 'vendor' */
+    char *          id;
+    char *          name;
+    char *          notes;
+    GncBillTerm *   terms;
+    GncAddress *    addr;
+    gnc_commodity * currency;
+    GncTaxTable*    taxtable;
+    gboolean        taxtable_override;
+    GncTaxIncluded  taxincluded;
+    gboolean        active;
+    GList *         jobs;
+
+    /* The following fields are unique to 'customer' */
+    gnc_numeric     credit;
+    gnc_numeric     discount;
+    GncAddress *    shipaddr;
+};
+
+struct _gncCustomerClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME        GNC_ID_CUSTOMER
+
+/* ============================================================== */
+/* misc inline funcs */
+
+G_INLINE_FUNC void mark_customer (GncCustomer *customer);
+void mark_customer (GncCustomer *customer)
+{
+    qof_instance_set_dirty(&customer->inst);
+    qof_event_gen (&customer->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* ============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncCustomer, gnc_customer, QOF_TYPE_INSTANCE);
+
+static void
+gnc_customer_init(GncCustomer* cust)
+{
+}
+
+static void
+gnc_customer_dispose(GObject *custp)
+{
+    G_OBJECT_CLASS(gnc_customer_parent_class)->dispose(custp);
+}
+
+static void
+gnc_customer_finalize(GObject* custp)
+{
+    G_OBJECT_CLASS(gnc_customer_parent_class)->finalize(custp);
+}
+
+static void
+gnc_customer_get_property (GObject         *object,
+                           guint            prop_id,
+                           GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncCustomer *cust;
+
+    g_return_if_fail(GNC_IS_CUSTOMER(object));
+
+    cust = GNC_CUSTOMER(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, cust->name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_customer_set_property (GObject         *object,
+                           guint            prop_id,
+                           const GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncCustomer *cust;
+
+    g_return_if_fail(GNC_IS_CUSTOMER(object));
+
+    cust = GNC_CUSTOMER(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncCustomerSetName(cust, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Return display name for this object */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncCustomer* cust;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
+
+    cust = GNC_CUSTOMER(inst);
+    /* XXX internationalization of "Customer" */
+    return g_strdup_printf("Customer %s", cust->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncCustomer* cust;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_CUSTOMER(inst), FALSE);
+
+    cust = GNC_CUSTOMER(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (cust->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        return (cust->taxtable == GNC_TAXTABLE(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_customer_class_init (GncCustomerClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_customer_dispose;
+    gobject_class->finalize = gnc_customer_finalize;
+    gobject_class->set_property = gnc_customer_set_property;
+    gobject_class->get_property = gnc_customer_get_property;
+
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "Customer Name",
+                          "The customer is an arbitrary string "
+                          "assigned by the user which provides the "
+                          "customer name.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncCustomer *gncCustomerCreate (QofBook *book)
+{
+    GncCustomer *cust;
+
+    if (!book) return NULL;
+
+    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
+    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
+
+    cust->id = CACHE_INSERT ("");
+    cust->name = CACHE_INSERT ("");
+    cust->notes = CACHE_INSERT ("");
+    cust->addr = gncAddressCreate (book, &cust->inst);
+    cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
+    cust->active = TRUE;
+    cust->jobs = NULL;
+
+    cust->discount = gnc_numeric_zero();
+    cust->credit = gnc_numeric_zero();
+    cust->shipaddr = gncAddressCreate (book, &cust->inst);
+
+    if (gs_address_event_handler_id == 0)
+    {
+        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+    }
+
+    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
+
+    return cust;
+}
+
+/** Create a copy of a customer, placing the copy into a new book. */
+GncCustomer *
+gncCloneCustomer (GncCustomer *from, QofBook *book)
+{
+    GList *node;
+    GncCustomer *cust;
+
+    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
+
+    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&cust->inst, &from->inst);
+
+    cust->id = CACHE_INSERT (from->id);
+    cust->name = CACHE_INSERT (from->name);
+    cust->notes = CACHE_INSERT (from->notes);
+    cust->discount = from->discount;
+    cust->credit = from->credit;
+    cust->taxincluded = from->taxincluded;
+    cust->active = from->active;
+    cust->taxtable_override = from->taxtable_override;
+
+    cust->addr = gncCloneAddress (from->addr, &cust->inst, book);
+    cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst, book);
+
+    /* Find the matching currency in the new book, assumes
+     * currency has already been copied into new book. */
+    cust->currency = gnc_commodity_obtain_twin (from->currency, book);
+
+    /* Find the matching bill term, tax table in the new book */
+    cust->terms = gncBillTermObtainTwin(from->terms, book);
+    cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
+
+    for (node = g_list_last(cust->jobs); node; node = node->next)
+    {
+        GncJob *job = node->data;
+        job = gncJobObtainTwin (job, book);
+        cust->jobs = g_list_prepend(cust->jobs, job);
+    }
+
+    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
+
+    return cust;
+}
+
+void gncCustomerDestroy (GncCustomer *cust)
+{
+    if (!cust) return;
+    qof_instance_set_destroying(cust, TRUE);
+    qof_instance_set_dirty (&cust->inst);
+    gncCustomerCommitEdit (cust);
+}
+
+static void gncCustomerFree (GncCustomer *cust)
+{
+    if (!cust) return;
+
+    qof_event_gen (&cust->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (cust->id);
+    CACHE_REMOVE (cust->name);
+    CACHE_REMOVE (cust->notes);
+    gncAddressBeginEdit (cust->addr);
+    gncAddressDestroy (cust->addr);
+    gncAddressBeginEdit (cust->shipaddr);
+    gncAddressDestroy (cust->shipaddr);
+    g_list_free (cust->jobs);
+
+    if (cust->terms)
+        gncBillTermDecRef (cust->terms);
+    if (cust->taxtable)
+    {
+        gncTaxTableDecRef (cust->taxtable);
+    }
+
+    /* qof_instance_release (&cust->inst); */
+    g_object_unref (cust);
+}
+
+GncCustomer *
+gncCustomerObtainTwin (GncCustomer *from, QofBook *book)
+{
+    GncCustomer *cust;
+    if (!from) return NULL;
+
+    cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!cust)
+    {
+        cust = gncCloneCustomer (from, book);
+    }
+    return cust;
+}
+
+/* ============================================================== */
+/* Set Functions */
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncCustomerBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+void gncCustomerSetID (GncCustomer *cust, const char *id)
+{
+    if (!cust) return;
+    if (!id) return;
+    SET_STR(cust, cust->id, id);
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetName (GncCustomer *cust, const char *name)
+{
+    if (!cust) return;
+    if (!name) return;
+    SET_STR(cust, cust->name, name);
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetNotes (GncCustomer *cust, const char *notes)
+{
+    if (!cust) return;
+    if (!notes) return;
+    SET_STR(cust, cust->notes, notes);
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetTerms (GncCustomer *cust, GncBillTerm *terms)
+{
+    if (!cust) return;
+    if (cust->terms == terms) return;
+
+    gncCustomerBeginEdit (cust);
+    if (cust->terms)
+        gncBillTermDecRef (cust->terms);
+    cust->terms = terms;
+    if (cust->terms)
+        gncBillTermIncRef (cust->terms);
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetTaxIncluded (GncCustomer *cust, GncTaxIncluded taxincl)
+{
+    if (!cust) return;
+    if (taxincl == cust->taxincluded) return;
+    gncCustomerBeginEdit (cust);
+    cust->taxincluded = taxincl;
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetActive (GncCustomer *cust, gboolean active)
+{
+    if (!cust) return;
+    if (active == cust->active) return;
+    gncCustomerBeginEdit (cust);
+    cust->active = active;
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetDiscount (GncCustomer *cust, gnc_numeric discount)
+{
+    if (!cust) return;
+    if (gnc_numeric_equal (discount, cust->discount)) return;
+    gncCustomerBeginEdit (cust);
+    cust->discount = discount;
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetCredit (GncCustomer *cust, gnc_numeric credit)
+{
+    if (!cust) return;
+    if (gnc_numeric_equal (credit, cust->credit)) return;
+    gncCustomerBeginEdit (cust);
+    cust->credit = credit;
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetCurrency (GncCustomer *cust, gnc_commodity *currency)
+{
+    if (!cust || !currency) return;
+    if (cust->currency && gnc_commodity_equal (cust->currency, currency)) return;
+    gncCustomerBeginEdit (cust);
+    cust->currency = currency;
+    mark_customer (cust);
+    gncCustomerCommitEdit (cust);
+}
+
+void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override)
+{
+    if (!customer) return;
+    if (customer->taxtable_override == override) return;
+    gncCustomerBeginEdit (customer);
+    customer->taxtable_override = override;
+    mark_customer (customer);
+    gncCustomerCommitEdit (customer);
+}
+
+void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table)
+{
+    if (!customer) return;
+    if (customer->taxtable == table) return;
+
+    gncCustomerBeginEdit (customer);
+    if (customer->taxtable)
+        gncTaxTableDecRef (customer->taxtable);
+    if (table)
+        gncTaxTableIncRef (table);
+    customer->taxtable = table;
+    mark_customer (customer);
+    gncCustomerCommitEdit (customer);
+}
+
+/* Note that JobList changes do not affect the "dirtiness" of the customer */
+void gncCustomerAddJob (GncCustomer *cust, GncJob *job)
+{
+    if (!cust) return;
+    if (!job) return;
+
+    if (g_list_index(cust->jobs, job) == -1)
+        cust->jobs = g_list_insert_sorted (cust->jobs, job,
+                                           (GCompareFunc)gncJobCompare);
+
+    qof_event_gen (&cust->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
+{
+    GList *node;
+
+    if (!cust) return;
+    if (!job) return;
+
+    node = g_list_find (cust->jobs, job);
+    if (!node)
+    {
+        /*    PERR ("split not in account"); */
+    }
+    else
+    {
+        cust->jobs = g_list_remove_link (cust->jobs, node);
+        g_list_free_1 (node);
+    }
+    qof_event_gen (&cust->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+void gncCustomerBeginEdit (GncCustomer *cust)
+{
+    qof_begin_edit (&cust->inst);
+}
+
+static void gncCustomerOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("Customer QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncCustomerOnDone (QofInstance *inst)
+{
+    GncCustomer *cust = (GncCustomer *) inst;
+    gncAddressClearDirty (cust->addr);
+    gncAddressClearDirty (cust->shipaddr);
+}
+
+static void cust_free (QofInstance *inst)
+{
+    GncCustomer *cust = (GncCustomer *) inst;
+    gncCustomerFree (cust);
+}
+
+void gncCustomerCommitEdit (GncCustomer *cust)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(cust))) return;
+    qof_commit_edit_part2 (&cust->inst, gncCustomerOnError,
+                           gncCustomerOnDone, cust_free);
+}
+
+/* ============================================================== */
+/* Get Functions */
+
+const char * gncCustomerGetID (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->id;
+}
+
+const char * gncCustomerGetName (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->name;
+}
+
+GncAddress * gncCustomerGetAddr (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->addr;
+}
+
+static void
+qofCustomerSetAddr (GncCustomer *cust, QofInstance *addr_ent)
+{
+    GncAddress *addr;
+
+    if (!cust || !addr_ent)
+    {
+        return;
+    }
+    addr = (GncAddress*)addr_ent;
+    if (addr == cust->addr)
+    {
+        return;
+    }
+    if (cust->addr != NULL)
+    {
+        gncAddressBeginEdit(cust->addr);
+        gncAddressDestroy(cust->addr);
+    }
+    gncCustomerBeginEdit(cust);
+    cust->addr = addr;
+    gncCustomerCommitEdit(cust);
+}
+
+static void
+qofCustomerSetShipAddr (GncCustomer *cust, QofInstance *ship_addr_ent)
+{
+    GncAddress *ship_addr;
+
+    if (!cust || !ship_addr_ent)
+    {
+        return;
+    }
+    ship_addr = (GncAddress*)ship_addr_ent;
+    if (ship_addr == cust->shipaddr)
+    {
+        return;
+    }
+    if (cust->shipaddr != NULL)
+    {
+        gncAddressBeginEdit(cust->shipaddr);
+        gncAddressDestroy(cust->shipaddr);
+    }
+    gncCustomerBeginEdit(cust);
+    cust->shipaddr = ship_addr;
+    gncCustomerCommitEdit(cust);
+}
+
+GncAddress * gncCustomerGetShipAddr (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->shipaddr;
+}
+
+const char * gncCustomerGetNotes (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->notes;
+}
+
+GncBillTerm * gncCustomerGetTerms (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->terms;
+}
+
+GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *cust)
+{
+    if (!cust) return GNC_TAXINCLUDED_USEGLOBAL;
+    return cust->taxincluded;
+}
+
+gnc_commodity * gncCustomerGetCurrency (const GncCustomer *cust)
+{
+    if (!cust) return NULL;
+    return cust->currency;
+}
+
+gboolean gncCustomerGetActive (const GncCustomer *cust)
+{
+    if (!cust) return FALSE;
+    return cust->active;
+}
+
+gnc_numeric gncCustomerGetDiscount (const GncCustomer *cust)
+{
+    if (!cust) return gnc_numeric_zero();
+    return cust->discount;
+}
+
+gnc_numeric gncCustomerGetCredit (const GncCustomer *cust)
+{
+    if (!cust) return gnc_numeric_zero();
+    return cust->credit;
+}
+
+gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer)
+{
+    if (!customer) return FALSE;
+    return customer->taxtable_override;
+}
+
+GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer)
+{
+    if (!customer) return NULL;
+    return customer->taxtable;
+}
+
+GList * gncCustomerGetJoblist (const GncCustomer *cust, gboolean show_all)
+{
+    if (!cust) return NULL;
+
+    if (show_all)
+    {
+        return (g_list_copy (cust->jobs));
+    }
+    else
+    {
+        GList *list = NULL, *iterator;
+        for (iterator = cust->jobs; iterator; iterator = iterator->next)
+        {
+            GncJob *j = iterator->data;
+            if (gncJobGetActive (j))
+                list = g_list_append (list, j);
+        }
+        return list;
+    }
+}
+
+gboolean gncCustomerIsDirty (GncCustomer *cust)
+{
+    if (!cust) return FALSE;
+    return (qof_instance_is_dirty(&cust->inst) ||
+            gncAddressIsDirty (cust->addr) ||
+            gncAddressIsDirty (cust->shipaddr));
+}
+
+/* Other functions */
+
+int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    return(strcmp(a->name, b->name));
+}
+
+gboolean
+gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_CUSTOMER(a), FALSE);
+    g_return_val_if_fail(GNC_IS_CUSTOMER(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("Names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->notes, b->notes) != 0)
+    {
+        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
+        return FALSE;
+    }
+
+    if (!gncBillTermEqual(a->terms, b->terms))
+    {
+        PWARN("Bill terms differ");
+        return FALSE;
+    }
+
+    if (!gnc_commodity_equal(a->currency, b->currency))
+    {
+        PWARN("currencies differ");
+        return FALSE;
+    }
+
+    if (!gncTaxTableEqual(a->taxtable, b->taxtable))
+    {
+        PWARN("tax tables differ");
+        return FALSE;
+    }
+
+    if (a->taxtable_override != b->taxtable_override)
+    {
+        PWARN("Tax table override flags differ");
+        return FALSE;
+    }
+
+    if (a->taxincluded != b->taxincluded)
+    {
+        PWARN("Tax included flags differ");
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+    if (!gncAddressEqual(a->addr, b->addr))
+    {
+        PWARN("addresses differ");
+        return FALSE;
+    }
+    if (!gncAddressEqual(a->shipaddr, b->shipaddr))
+    {
+        PWARN("addresses differ");
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->credit, b->credit))
+    {
+        PWARN("Credit amounts differ");
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->discount, b->discount))
+    {
+        PWARN("Discount amounts differ");
+        return FALSE;
+    }
+
+    /* FIXME: Need to check jobs list
+    GList *         jobs;
+    */
+
+    return TRUE;
+}
+
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to a customer,
+ * mark the customer as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                          gpointer user_data, gpointer event_data)
+{
+    GncCustomer* cust;
+
+    if ((event_type & QOF_EVENT_MODIFY) == 0)
+    {
+        return;
+    }
+    if (!GNC_IS_ADDRESS(entity))
+    {
+        return;
+    }
+    if (!GNC_IS_CUSTOMER(event_data))
+    {
+        return;
+    }
+    cust = GNC_CUSTOMER(event_data);
+    gncCustomerBeginEdit(cust);
+    mark_customer(cust);
+    gncCustomerCommitEdit(cust);
+}
+/* ============================================================== */
+/* Package-Private functions */
+static const char * _gncCustomerPrintable (gpointer item)
+{
+//  GncCustomer *c = item;
+    if (!item) return "failed";
+    return gncCustomerGetName((GncCustomer*)item);
+}
+
+static QofObject gncCustomerDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Customer",
+    DI(.create            = ) (gpointer)gncCustomerCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) (const char * (*)(gpointer))gncCustomerGetName,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncCustomerRegister (void)
+{
+    static QofParam params[] =
+    {
+        { CUSTOMER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetID, (QofSetterFunc)gncCustomerSetID },
+        { CUSTOMER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetName, (QofSetterFunc)gncCustomerSetName },
+        { CUSTOMER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetNotes, (QofSetterFunc)gncCustomerSetNotes },
+        {
+            CUSTOMER_DISCOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc)gncCustomerGetDiscount,
+            (QofSetterFunc)gncCustomerSetDiscount
+        },
+        {
+            CUSTOMER_CREDIT, QOF_TYPE_NUMERIC, (QofAccessFunc)gncCustomerGetCredit,
+            (QofSetterFunc)gncCustomerSetCredit
+        },
+        { CUSTOMER_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncCustomerGetAddr, (QofSetterFunc)qofCustomerSetAddr },
+        { CUSTOMER_SHIPADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncCustomerGetShipAddr, (QofSetterFunc)qofCustomerSetShipAddr },
+        {
+            CUSTOMER_TT_OVER, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetTaxTableOverride,
+            (QofSetterFunc)gncCustomerSetTaxTableOverride
+        },
+        { CUSTOMER_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncCustomerGetTerms, (QofSetterFunc)gncCustomerSetTerms },
+        { CUSTOMER_SLOTS, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive, (QofSetterFunc)gncCustomerSetActive },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_CUSTOMER, INVOICE_OWNER))
+    {
+        return FALSE;
+    }
+    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_CUSTOMER, JOB_OWNER))
+    {
+        return FALSE;
+    }
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare, params);
+    if (!qof_choice_create(GNC_ID_CUSTOMER))
+    {
+        return FALSE;
+    }
+    /* temp */
+    _gncCustomerPrintable(NULL);
+    return qof_object_register (&gncCustomerDesc);
+}
+
+gint64 gncCustomerNextID (QofBook *book)
+{
+    return qof_book_get_counter (book, _GNC_MOD_NAME);
+}

Copied: gnucash/trunk/src/engine/gncCustomer.h (from rev 19328, gnucash/trunk/src/business/business-core/gncCustomer.h)
===================================================================
--- gnucash/trunk/src/engine/gncCustomer.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncCustomer.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,166 @@
+/********************************************************************\
+ * gncCustomer.h -- the Core Customer Interface                     *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Customer
+    @{ */
+/** @file gncCustomer.h
+    @brief Core Customer Interface
+    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_CUSTOMER_H_
+#define GNC_CUSTOMER_H_
+
+/** @struct GncCustomer
+
+credit, discount and shipaddr are unique to GncCustomer\n
+id, name, notes, terms, addr, currency, taxtable, taxtable_override
+taxincluded, active and jobs are identical to ::GncVendor.
+
+ at param	QofInstance     inst;
+ at param	char *          id;
+ at param	char *          name;
+ at param	char *          notes;
+ at param	GncBillTerm *   terms;
+ at param	GncAddress *    addr;
+ at param	gnc_commodity * currency;
+ at param	GncTaxTable*    taxtable;
+ at param	gboolean        taxtable_override;
+ at param	GncTaxIncluded  taxincluded;
+ at param	gboolean        active;
+ at param	GList *         jobs;
+ at param	gnc_numeric     credit;
+ at param	gnc_numeric     discount;
+ at param	GncAddress *    shipaddr;
+
+*/
+typedef struct _gncCustomer GncCustomer;
+typedef struct _gncCustomerClass GncCustomerClass;
+
+#include "gncAddress.h"
+#include "gncBillTerm.h"
+#include "gncTaxTable.h"
+#include "gncJob.h"
+
+#define GNC_ID_CUSTOMER       "gncCustomer"
+
+/* --- type macros --- */
+#define GNC_TYPE_CUSTOMER            (gnc_customer_get_type ())
+#define GNC_CUSTOMER(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_CUSTOMER, GncCustomer))
+#define GNC_CUSTOMER_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_CUSTOMER, GncCustomerClass))
+#define GNC_IS_CUSTOMER(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_CUSTOMER))
+#define GNC_IS_CUSTOMER_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_CUSTOMER))
+#define GNC_CUSTOMER_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_CUSTOMER, GncCustomerClass))
+GType gnc_customer_get_type(void);
+
+/** @name Create/Destroy Functions
+ @{ */
+GncCustomer *gncCustomerCreate (QofBook *book);
+void gncCustomerDestroy (GncCustomer *customer);
+void gncCustomerBeginEdit (GncCustomer *customer);
+void gncCustomerCommitEdit (GncCustomer *customer);
+/** @} */
+
+/** @name Set Functions
+ @{ */
+
+void gncCustomerSetID (GncCustomer *customer, const char *id);
+void gncCustomerSetName (GncCustomer *customer, const char *name);
+void gncCustomerSetNotes (GncCustomer *customer, const char *notes);
+void gncCustomerSetTerms (GncCustomer *customer, GncBillTerm *term);
+void gncCustomerSetTaxIncluded (GncCustomer *customer, GncTaxIncluded taxincl);
+void gncCustomerSetActive (GncCustomer *customer, gboolean active);
+void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount);
+void gncCustomerSetCredit (GncCustomer *customer, gnc_numeric credit);
+void gncCustomerSetCurrency (GncCustomer *customer, gnc_commodity *currency);
+
+void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override);
+void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table);
+
+void gncCustomerAddJob (GncCustomer *customer, GncJob *job);
+void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job);
+
+/** @} */
+
+/** @name Get Functions
+ @{ */
+/** Return a pointer to the instance gncCustomer that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncCustomer * gncCustomerLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncCustomer * gncCustomerLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_CUSTOMER, GncCustomer);
+}
+
+const char * gncCustomerGetID (const GncCustomer *customer);
+const char * gncCustomerGetName (const GncCustomer *customer);
+GncAddress * gncCustomerGetAddr (const GncCustomer *customer);
+GncAddress * gncCustomerGetShipAddr (const GncCustomer *customer);
+const char * gncCustomerGetNotes (const GncCustomer *customer);
+GncBillTerm * gncCustomerGetTerms (const GncCustomer *customer);
+GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *customer);
+gboolean gncCustomerGetActive (const GncCustomer *customer);
+gnc_numeric gncCustomerGetDiscount (const GncCustomer *customer);
+gnc_numeric gncCustomerGetCredit (const GncCustomer *customer);
+gnc_commodity * gncCustomerGetCurrency (const GncCustomer *customer);
+
+gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer);
+GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer);
+
+GList * gncCustomerGetJoblist (const GncCustomer *customer, gboolean show_all);
+/** @} */
+
+gboolean gncCustomerIsDirty (GncCustomer *customer);
+int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b);
+gboolean gncCustomerEqual(const GncCustomer *a, const GncCustomer *b);
+
+#define CUSTOMER_ID			"id"
+#define CUSTOMER_NAME		"name"
+#define CUSTOMER_ADDR		"addr"
+#define CUSTOMER_SHIPADDR	"shipaddr"
+#define CUSTOMER_NOTES 		"notes"
+#define CUSTOMER_DISCOUNT 	"amount of discount"
+#define CUSTOMER_CREDIT 	"amount of credit"
+#define CUSTOMER_TT_OVER 	"tax table override"
+#define CUSTOMER_TAX_INC    "customer_tax_included"
+#define CUSTOMER_TERMS      "customer_terms"
+#define CUSTOMER_ACTIVE     "customer_is_active"
+#define CUSTOMER_SLOTS      "customer_values"
+
+/** @deprecated functions, should be removed */
+#define gncCustomerGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+#define gncCustomerRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
+#define gncCustomerGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
+#define gncCustomerLookupDirect(g,b) gncCustomerLookup((b), &(g))
+
+#endif /* GNC_CUSTOMER_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncCustomerP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncCustomerP.h)
===================================================================
--- gnucash/trunk/src/engine/gncCustomerP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncCustomerP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,58 @@
+/********************************************************************\
+ * gncCustomerP.h -- the Core Customer Interface                    *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_CUSTOMERP_H_
+#define GNC_CUSTOMERP_H_
+
+#include "gncCustomer.h"
+
+gboolean gncCustomerRegister (void);
+gint64 gncCustomerNextID (QofBook *book);
+
+/** The gncCloneCustomer() routine makes a copy of the indicated
+ *  customer, placing it in the indicated book.  It copies
+ *  the addresses, credits, currency, billing terms and jobs.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+GncCustomer * gncCloneCustomer (GncCustomer *from,  QofBook *book);
+
+/** The gncCustomerObtainTwin() will find the 'twin' of the
+ *  indicated customer in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneCustomer()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncCustomer * gncCustomerObtainTwin (GncCustomer *from, QofBook *book);
+
+#define gncCustomerSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+#endif /* GNC_CUSTOMERP_H_ */

Copied: gnucash/trunk/src/engine/gncEmployee.c (from rev 19328, gnucash/trunk/src/business/business-core/gncEmployee.c)
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEmployee.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,724 @@
+/********************************************************************\
+ * gncEmployee.c -- the Core Employee Interface                     *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001,2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>
+
+#include "Account.h"
+#include "gnc-commodity.h"
+#include "gncAddressP.h"
+#include "gncEmployee.h"
+#include "gncEmployeeP.h"
+
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                                      gpointer user_data, gpointer event_data);
+
+struct _gncEmployee
+{
+    QofInstance     inst;
+    char *          id;
+    char *          username;
+    GncAddress *    addr;
+    gnc_commodity * currency;
+    gboolean        active;
+
+    char *          language;
+    char *          acl;
+    gnc_numeric     workday;
+    gnc_numeric     rate;
+
+    Account *        ccard_acc;
+};
+
+struct _gncEmployeeClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME        GNC_ID_EMPLOYEE
+
+G_INLINE_FUNC void mark_employee (GncEmployee *employee);
+void mark_employee (GncEmployee *employee)
+{
+    qof_instance_set_dirty(&employee->inst);
+    qof_event_gen (&employee->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* ============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_USERNAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncEmployee, gnc_employee, QOF_TYPE_INSTANCE);
+
+static void
+gnc_employee_init(GncEmployee* emp)
+{
+}
+
+static void
+gnc_employee_dispose(GObject *empp)
+{
+    G_OBJECT_CLASS(gnc_employee_parent_class)->dispose(empp);
+}
+
+static void
+gnc_employee_finalize(GObject* empp)
+{
+    G_OBJECT_CLASS(gnc_employee_parent_class)->finalize(empp);
+}
+
+static void
+gnc_employee_get_property (GObject         *object,
+                           guint            prop_id,
+                           GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncEmployee *emp;
+
+    g_return_if_fail(GNC_IS_EMPLOYEE(object));
+
+    emp = GNC_EMPLOYEE(object);
+    switch (prop_id)
+    {
+    case PROP_USERNAME:
+        g_value_set_string(value, emp->username);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_employee_set_property (GObject         *object,
+                           guint            prop_id,
+                           const GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncEmployee *emp;
+
+    g_return_if_fail(GNC_IS_EMPLOYEE(object));
+
+    emp = GNC_EMPLOYEE(object);
+    switch (prop_id)
+    {
+    case PROP_USERNAME:
+        gncEmployeeSetUsername(emp, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Get displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncEmployee* emp;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
+
+    emp = GNC_EMPLOYEE(inst);
+    return g_strdup_printf("Employee %s", emp->username);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncEmployee* emp;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
+
+    emp = GNC_EMPLOYEE(inst);
+
+    if (GNC_IS_COMMODITY(ref))
+    {
+        return (emp->currency == GNC_COMMODITY(ref));
+    }
+    else if (GNC_IS_ACCOUNT(ref))
+    {
+        return (emp->ccard_acc == GNC_ACCOUNT(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_employee_class_init (GncEmployeeClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_employee_dispose;
+    gobject_class->finalize = gnc_employee_finalize;
+    gobject_class->set_property = gnc_employee_set_property;
+    gobject_class->get_property = gnc_employee_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_USERNAME,
+     g_param_spec_string ("username",
+                          "Employee Name",
+                          "The employee name is an arbitrary string "
+                          "assigned by the user which provides the employee "
+                          "name.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncEmployee *gncEmployeeCreate (QofBook *book)
+{
+    GncEmployee *employee;
+
+    if (!book) return NULL;
+
+    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
+    qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);
+
+    employee->id = CACHE_INSERT ("");
+    employee->username = CACHE_INSERT ("");
+    employee->language = CACHE_INSERT ("");
+    employee->acl = CACHE_INSERT ("");
+    employee->addr = gncAddressCreate (book, &employee->inst);
+    employee->workday = gnc_numeric_zero();
+    employee->rate = gnc_numeric_zero();
+    employee->active = TRUE;
+
+    if (gs_address_event_handler_id == 0)
+    {
+        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+    }
+
+    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
+
+    return employee;
+}
+
+void gncEmployeeDestroy (GncEmployee *employee)
+{
+    if (!employee) return;
+    qof_instance_set_destroying(employee, TRUE);
+    gncEmployeeCommitEdit(employee);
+}
+
+static void gncEmployeeFree (GncEmployee *employee)
+{
+    if (!employee) return;
+
+    qof_event_gen (&employee->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (employee->id);
+    CACHE_REMOVE (employee->username);
+    CACHE_REMOVE (employee->language);
+    CACHE_REMOVE (employee->acl);
+    gncAddressBeginEdit (employee->addr);
+    gncAddressDestroy (employee->addr);
+
+    /* qof_instance_release (&employee->inst); */
+    g_object_unref (employee);
+}
+
+GncEmployee *
+gncCloneEmployee (GncEmployee *from, QofBook *book)
+{
+    GncEmployee *employee;
+    if (!book || !from) return NULL;
+
+    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
+    qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&employee->inst, &from->inst);
+
+    employee->id = CACHE_INSERT (from->id);
+    employee->username = CACHE_INSERT (from->username);
+    employee->language = CACHE_INSERT (from->language);
+    employee->acl = CACHE_INSERT (from->acl);
+    employee->addr = gncCloneAddress (from->addr, &employee->inst, book);
+    employee->workday = from->workday;
+    employee->rate = from->rate;
+    employee->active = from->active;
+    employee->currency = gnc_commodity_obtain_twin(from->currency, book);
+    employee->ccard_acc =
+        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));
+
+    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
+
+    return employee;
+}
+
+GncEmployee *
+gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
+{
+    GncEmployee *employee;
+    if (!book) return NULL;
+
+    employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!employee)
+    {
+        employee = gncCloneEmployee (from, book);
+    }
+
+    return employee;
+}
+
+/* ============================================================== */
+/* Set Functions */
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncEmployeeBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+void gncEmployeeSetID (GncEmployee *employee, const char *id)
+{
+    if (!employee) return;
+    if (!id) return;
+    SET_STR(employee, employee->id, id);
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetUsername (GncEmployee *employee, const char *username)
+{
+    if (!employee) return;
+    if (!username) return;
+    SET_STR(employee, employee->username, username);
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetLanguage (GncEmployee *employee, const char *language)
+{
+    if (!employee) return;
+    if (!language) return;
+    SET_STR(employee, employee->language, language);
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetAcl (GncEmployee *employee, const char *acl)
+{
+    if (!employee) return;
+    if (!acl) return;
+    SET_STR(employee, employee->acl, acl);
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday)
+{
+    if (!employee) return;
+    if (gnc_numeric_equal (workday, employee->workday)) return;
+    gncEmployeeBeginEdit (employee);
+    employee->workday = workday;
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate)
+{
+    if (!employee) return;
+    if (gnc_numeric_equal (rate, employee->rate)) return;
+    gncEmployeeBeginEdit (employee);
+    employee->rate = rate;
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency)
+{
+    if (!employee || !currency) return;
+    if (employee->currency &&
+            gnc_commodity_equal (employee->currency, currency))
+        return;
+    gncEmployeeBeginEdit (employee);
+    employee->currency = currency;
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetActive (GncEmployee *employee, gboolean active)
+{
+    if (!employee) return;
+    if (active == employee->active) return;
+    gncEmployeeBeginEdit (employee);
+    employee->active = active;
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc)
+{
+    if (!employee) return;
+    if (ccard_acc == employee->ccard_acc) return;
+    gncEmployeeBeginEdit (employee);
+    employee->ccard_acc = ccard_acc;
+    mark_employee (employee);
+    gncEmployeeCommitEdit (employee);
+}
+
+void
+qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent)
+{
+    GncAddress *addr;
+
+    if (!employee || !addr_ent)
+    {
+        return;
+    }
+    addr = (GncAddress*)addr_ent;
+    if (addr == employee->addr)
+    {
+        return;
+    }
+    if (employee->addr != NULL)
+    {
+        gncAddressBeginEdit(employee->addr);
+        gncAddressDestroy(employee->addr);
+    }
+    gncEmployeeBeginEdit(employee);
+    employee->addr = addr;
+    gncEmployeeCommitEdit(employee);
+}
+
+/* ============================================================== */
+/* Get Functions */
+const char * gncEmployeeGetID (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->id;
+}
+
+const char * gncEmployeeGetUsername (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->username;
+}
+
+GncAddress * gncEmployeeGetAddr (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->addr;
+}
+
+const char * gncEmployeeGetLanguage (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->language;
+}
+
+const char * gncEmployeeGetAcl (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->acl;
+}
+
+gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee)
+{
+    if (!employee) return gnc_numeric_zero();
+    return employee->workday;
+}
+
+gnc_numeric gncEmployeeGetRate (const GncEmployee *employee)
+{
+    if (!employee) return gnc_numeric_zero();
+    return employee->rate;
+}
+
+gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->currency;
+}
+
+gboolean gncEmployeeGetActive (const GncEmployee *employee)
+{
+    if (!employee) return FALSE;
+    return employee->active;
+}
+
+Account * gncEmployeeGetCCard (const GncEmployee *employee)
+{
+    if (!employee) return NULL;
+    return employee->ccard_acc;
+}
+
+gboolean gncEmployeeIsDirty (const GncEmployee *employee)
+{
+    if (!employee) return FALSE;
+    return (qof_instance_get_dirty_flag(employee)
+            || gncAddressIsDirty (employee->addr));
+}
+
+void gncEmployeeBeginEdit (GncEmployee *employee)
+{
+    qof_begin_edit(&employee->inst);
+}
+
+static void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode)
+{
+    PERR("Employee QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncEmployeeOnDone (QofInstance *inst)
+{
+    GncEmployee *employee = (GncEmployee *) inst;
+    gncAddressClearDirty (employee->addr);
+}
+
+static void emp_free (QofInstance *inst)
+{
+    GncEmployee *employee = (GncEmployee *) inst;
+    gncEmployeeFree (employee);
+}
+
+
+void gncEmployeeCommitEdit (GncEmployee *employee)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(employee))) return;
+    qof_commit_edit_part2 (&employee->inst, gncEmployeeOnError,
+                           gncEmployeeOnDone, emp_free);
+}
+
+/* ============================================================== */
+/* Other functions */
+
+int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    return(strcmp(a->username, b->username));
+}
+
+gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL ) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE);
+    g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->username, b->username) != 0)
+    {
+        PWARN("Usernames differ: %s vs %s", a->username, b->username);
+        return FALSE;
+    }
+
+    if (!gncAddressEqual(a->addr, b->addr))
+    {
+        PWARN("Addresses differ");
+        return FALSE;
+    }
+
+    if (!gnc_commodity_equal(a->currency, b->currency))
+    {
+        PWARN("Currencies differ");
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->language, b->language) != 0)
+    {
+        PWARN("Languages differ: %s vs %s", a->language, b->language);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->acl, b->acl) != 0)
+    {
+        PWARN("ACLs differ: %s vs %s", a->acl, b->acl);
+        return FALSE;
+    }
+
+    if (!xaccAccountEqual(a->ccard_acc, b->ccard_acc, TRUE))
+    {
+        PWARN("Accounts differ");
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->workday, b->workday))
+    {
+        PWARN("Workdays differ");
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->rate, b->rate))
+    {
+        PWARN("Rates differ");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+/* Package-Private functions */
+
+static const char * _gncEmployeePrintable (gpointer item)
+{
+    GncEmployee *v = item;
+    if (!item) return NULL;
+    return gncAddressGetName(v->addr);
+}
+
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to an employee,
+ * mark the employee as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                          gpointer user_data, gpointer event_data)
+{
+    GncEmployee* empl;
+
+    if ((event_type & QOF_EVENT_MODIFY) == 0)
+    {
+        return;
+    }
+    if (!GNC_IS_ADDRESS(entity))
+    {
+        return;
+    }
+    if (!GNC_IS_EMPLOYEE(event_data))
+    {
+        return;
+    }
+    empl = GNC_EMPLOYEE(event_data);
+    gncEmployeeBeginEdit(empl);
+    mark_employee(empl);
+    gncEmployeeCommitEdit(empl);
+}
+
+static QofObject gncEmployeeDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Employee",
+    DI(.create            = ) (gpointer)gncEmployeeCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) _gncEmployeePrintable,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncEmployeeRegister (void)
+{
+    static QofParam params[] =
+    {
+        { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, (QofSetterFunc)gncEmployeeSetID },
+        {
+            EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername,
+            (QofSetterFunc)gncEmployeeSetUsername
+        },
+        {
+            EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage,
+            (QofSetterFunc)gncEmployeeSetLanguage
+        },
+        { EMPLOYEE_ACL, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetAcl, (QofSetterFunc)gncEmployeeSetAcl },
+        {
+            EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetWorkday,
+            (QofSetterFunc)gncEmployeeSetWorkday
+        },
+        { EMPLOYEE_RATE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetRate, (QofSetterFunc)gncEmployeeSetRate },
+        { EMPLOYEE_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncEmployeeGetAddr, (QofSetterFunc)qofEmployeeSetAddr },
+        { EMPLOYEE_CC,  GNC_ID_ACCOUNT, (QofAccessFunc)gncEmployeeGetCCard, (QofSetterFunc)gncEmployeeSetCCard },
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params);
+
+    return qof_object_register (&gncEmployeeDesc);
+}
+
+gint64 gncEmployeeNextID (QofBook *book)
+{
+    return qof_book_get_counter (book, _GNC_MOD_NAME);
+}

Copied: gnucash/trunk/src/engine/gncEmployee.h (from rev 19328, gnucash/trunk/src/business/business-core/gncEmployee.h)
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEmployee.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,127 @@
+/********************************************************************\
+ * gncEmployee.h -- the Core Employee Interface                     *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Employee
+    @{ */
+/** @file gncEmployee.h
+    @brief Employee Interface
+    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_EMPLOYEE_H_
+#define GNC_EMPLOYEE_H_
+
+typedef struct _gncEmployee GncEmployee;
+typedef struct _gncEmployeeClass GncEmployeeClass;
+
+#include "gncAddress.h"
+#include "Account.h"
+
+#define GNC_ID_EMPLOYEE "gncEmployee"
+
+/* --- type macros --- */
+#define GNC_TYPE_EMPLOYEE            (gnc_employee_get_type ())
+#define GNC_EMPLOYEE(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_EMPLOYEE, GncEmployee))
+#define GNC_EMPLOYEE_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_EMPLOYEE, GncEmployeeClass))
+#define GNC_IS_EMPLOYEE(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_EMPLOYEE))
+#define GNC_IS_EMPLOYEE_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_EMPLOYEE))
+#define GNC_EMPLOYEE_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_EMPLOYEE, GncEmployeeClass))
+GType gnc_employee_get_type(void);
+
+/** @name Create/Destroy Functions
+ @{ */
+GncEmployee *gncEmployeeCreate (QofBook *book);
+void gncEmployeeDestroy (GncEmployee *employee);
+void gncEmployeeBeginEdit (GncEmployee *employee);
+void gncEmployeeCommitEdit (GncEmployee *employee);
+int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b);
+/** @} */
+
+/** @name Set Functions
+ @{ */
+void gncEmployeeSetID (GncEmployee *employee, const char *id);
+void gncEmployeeSetUsername (GncEmployee *employee, const char *username);
+void gncEmployeeSetLanguage (GncEmployee *employee, const char *language);
+void gncEmployeeSetAcl (GncEmployee *employee, const char *acl);
+void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday);
+void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate);
+void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity * currency);
+void gncEmployeeSetActive (GncEmployee *employee, gboolean active);
+void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc);
+void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent);
+
+/** @} */
+
+/** @name Get Functions
+ @{ */
+QofBook * gncEmployeeGetBook (GncEmployee *employee);
+const char * gncEmployeeGetID (const GncEmployee *employee);
+const char * gncEmployeeGetUsername (const GncEmployee *employee);
+GncAddress * gncEmployeeGetAddr (const GncEmployee *employee);
+const char * gncEmployeeGetLanguage (const GncEmployee *employee);
+const char * gncEmployeeGetAcl (const GncEmployee *employee);
+gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee);
+gnc_numeric gncEmployeeGetRate (const GncEmployee *employee);
+gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee);
+gboolean gncEmployeeGetActive (const GncEmployee *employee);
+Account * gncEmployeeGetCCard (const GncEmployee *employee);
+/** @} */
+
+
+/** Return a pointer to the instance gncEmployee that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncEmployee * gncEmployeeLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncEmployee * gncEmployeeLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_EMPLOYEE, GncEmployee);
+}
+
+gboolean gncEmployeeIsDirty (const GncEmployee *employee);
+gboolean gncEmployeeEqual(const GncEmployee* e1, const GncEmployee* e2);
+
+#define EMPLOYEE_ID			"id"
+#define EMPLOYEE_USERNAME	"username"
+#define EMPLOYEE_ADDR		"addr"
+#define EMPLOYEE_LANGUAGE 	"native language"
+#define EMPLOYEE_ACL		"acl"
+#define EMPLOYEE_WORKDAY	"workday"
+#define EMPLOYEE_RATE		"rate"
+#define EMPLOYEE_CC    "credit_card_account"
+
+/** deprecated routines */
+#define gncEmployeeGetGUID(E) qof_entity_get_guid(QOF_INSTANCE(E))
+#define gncEmployeeGetBook(E) qof_instance_get_book(QOF_INSTANCE(E))
+#define gncEmployeeRetGUID(E) (E ? *(qof_entity_get_guid(QOF_INSTANCE(E))) : *(guid_null()))
+#define gncEmployeeLookupDirect(G,B) gncEmployeeLookup((B),&(G))
+
+#endif /* GNC_EMPLOYEE_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncEmployeeP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncEmployeeP.h)
===================================================================
--- gnucash/trunk/src/engine/gncEmployeeP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEmployeeP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,62 @@
+/********************************************************************\
+ * gncEmployeeP.h -- the Core Employee Interface
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_EMPLOYEEP_H_
+#define GNC_EMPLOYEEP_H_
+
+#include "gncEmployee.h"
+
+gboolean gncEmployeeRegister (void);
+gint64 gncEmployeeNextID (QofBook *book);
+
+/** The gncCloneEmployee() routine makes a copy of the indicated
+ *  employee, placing it in the indicated book.  It copies
+ *  the username, address, currency, ccard account, etc.
+ *  It also copies (as needed) both parents and children, so that
+ *  the parent-child relationship is correctly mirrored in the
+ *  clone.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *);
+
+/** The gncEmployeeObtainTwin() will find the 'twin' of the
+ *  indicated employee in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneEmployee()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book);
+
+#define gncEmployeeSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+#endif /* GNC_EMPLOYEEP_H_ */

Copied: gnucash/trunk/src/engine/gncEntry.c (from rev 19328, gnucash/trunk/src/business/business-core/gncEntry.c)
===================================================================
--- gnucash/trunk/src/engine/gncEntry.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEntry.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,1602 @@
+/********************************************************************\
+ * gncEntry.c -- the Core Business Entry Interface                  *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001,2002 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "gnc-commodity.h"
+
+#include "gncEntry.h"
+#include "gncEntryP.h"
+#include "gncInvoice.h"
+#include "gncOrder.h"
+
+struct _gncEntry
+{
+    QofInstance inst;
+
+    Timespec	date;
+    Timespec	date_entered;
+    char *	desc;
+    char *	action;
+    char *	notes;
+    gnc_numeric 	quantity;
+
+    /* customer invoice data */
+    Account *	i_account;
+    gnc_numeric 	i_price;
+    gboolean	i_taxable;
+    gboolean	i_taxincluded;
+    GncTaxTable *	i_tax_table;
+    gnc_numeric 	i_discount;
+    GncAmountType	i_disc_type;
+    GncDiscountHow i_disc_how;
+
+    /* vendor bill data */
+    Account *	b_account;
+    gnc_numeric 	b_price;
+    gboolean	b_taxable;
+    gboolean	b_taxincluded;
+    GncTaxTable *	b_tax_table;
+    gboolean	billable;
+    GncOwner	billto;
+
+    /* employee bill data */
+    GncEntryPaymentType b_payment;
+
+    /* my parent(s) */
+    GncOrder *	order;
+    GncInvoice *	invoice;
+    GncInvoice *	bill;
+
+    /* CACHED VALUES */
+    gboolean	values_dirty;
+
+    /* customer invoice */
+    gnc_numeric	i_value;
+    gnc_numeric	i_value_rounded;
+    GList *	i_tax_values;
+    gnc_numeric	i_tax_value;
+    gnc_numeric	i_tax_value_rounded;
+    gnc_numeric	i_disc_value;
+    gnc_numeric	i_disc_value_rounded;
+    Timespec	i_taxtable_modtime;
+
+    /* vendor bill */
+    gnc_numeric	b_value;
+    gnc_numeric	b_value_rounded;
+    GList *	b_tax_values;
+    gnc_numeric	b_tax_value;
+    gnc_numeric	b_tax_value_rounded;
+    Timespec	b_taxtable_modtime;
+};
+
+struct _gncEntryClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+/* You must edit the functions in this block in tandem.  KEEP THEM IN
+   SYNC! */
+
+#define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);
+const char *
+gncEntryDiscountHowToString (GncDiscountHow how)
+{
+    switch (how)
+    {
+        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_PRETAX, "PRETAX");
+        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_SAMETIME, "SAMETIME");
+        GNC_RETURN_ENUM_AS_STRING(GNC_DISC_POSTTAX, "POSTTAX");
+    default:
+        g_warning ("asked to translate unknown discount-how %d.\n", how);
+        break;
+    }
+    return(NULL);
+}
+
+const char * gncEntryPaymentTypeToString (GncEntryPaymentType type)
+{
+    switch (type)
+    {
+        GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CASH, "CASH");
+        GNC_RETURN_ENUM_AS_STRING(GNC_PAYMENT_CARD, "CARD");
+    default:
+        g_warning ("asked to translate unknown payment type %d.\n", type);
+        break;
+    }
+    return(NULL);
+}
+#undef GNC_RETURN_ENUM_AS_STRING
+#define GNC_RETURN_ON_MATCH(s,x,r) \
+  if(safe_strcmp((s), (str)) == 0) { *(r) = x; return(TRUE); }
+gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how)
+{
+    GNC_RETURN_ON_MATCH ("PRETAX", GNC_DISC_PRETAX, how);
+    GNC_RETURN_ON_MATCH ("SAMETIME", GNC_DISC_SAMETIME, how);
+    GNC_RETURN_ON_MATCH ("POSTTAX", GNC_DISC_POSTTAX, how);
+    g_warning ("asked to translate unknown discount-how string %s.\n",
+               str ? str : "(null)");
+
+    return(FALSE);
+}
+gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type)
+{
+    GNC_RETURN_ON_MATCH ("CASH", GNC_PAYMENT_CASH, type);
+    GNC_RETURN_ON_MATCH ("CARD", GNC_PAYMENT_CARD, type);
+    g_warning ("asked to translate unknown discount-how string %s.\n",
+               str ? str : "(null)");
+
+    return(FALSE);
+}
+#undef GNC_RETURN_ON_MATCH
+
+#define _GNC_MOD_NAME	GNC_ID_ENTRY
+
+#define SET_STR(obj, member, str) { \
+	char * tmp; \
+	\
+	if (!safe_strcmp (member, str)) return; \
+	gncEntryBeginEdit (obj); \
+	tmp = CACHE_INSERT (str); \
+	CACHE_REMOVE (member); \
+	member = tmp; \
+	}
+
+G_INLINE_FUNC void mark_entry (GncEntry *entry);
+void mark_entry (GncEntry *entry)
+{
+    qof_instance_set_dirty(&entry->inst);
+    qof_event_gen (&entry->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* ================================================================ */
+
+enum
+{
+    PROP_0,
+    PROP_DESCRIPTION
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncEntry, gnc_entry, QOF_TYPE_INSTANCE);
+
+static void
+gnc_entry_init(GncEntry* entry)
+{
+}
+
+static void
+gnc_entry_dispose(GObject *entryp)
+{
+    G_OBJECT_CLASS(gnc_entry_parent_class)->dispose(entryp);
+}
+
+static void
+gnc_entry_finalize(GObject* entryp)
+{
+    G_OBJECT_CLASS(gnc_entry_parent_class)->finalize(entryp);
+}
+
+static void
+gnc_entry_get_property (GObject         *object,
+                        guint            prop_id,
+                        GValue          *value,
+                        GParamSpec      *pspec)
+{
+    GncEntry *entry;
+
+    g_return_if_fail(GNC_IS_ENTRY(object));
+
+    entry = GNC_ENTRY(object);
+    switch (prop_id)
+    {
+    case PROP_DESCRIPTION:
+        g_value_set_string(value, entry->desc);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_entry_set_property (GObject         *object,
+                        guint            prop_id,
+                        const GValue          *value,
+                        GParamSpec      *pspec)
+{
+    GncEntry *entry;
+
+    g_return_if_fail(GNC_IS_ENTRY(object));
+
+    entry = GNC_ENTRY(object);
+    switch (prop_id)
+    {
+    case PROP_DESCRIPTION:
+        gncEntrySetDescription(entry, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncEntry* entry;
+    gchar* display_name;
+    gchar* s;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
+
+    entry = GNC_ENTRY(inst);
+    if (entry->order != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->order));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+    if (entry->invoice != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->invoice));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+    if (entry->bill != NULL)
+    {
+        display_name = qof_instance_get_display_name(QOF_INSTANCE(entry->bill));
+        s = g_strdup_printf("Entry in %s", display_name);
+        g_free(display_name);
+        return s;
+    }
+
+    return g_strdup_printf("Entry %p", inst);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncEntry* entry;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_ENTRY(inst), FALSE);
+
+    entry = GNC_ENTRY(inst);
+
+    if (GNC_IS_ACCOUNT(ref))
+    {
+        Account* acc = GNC_ACCOUNT(ref);
+        return (entry->i_account == acc || entry->b_account == acc);
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        GncTaxTable* tt = GNC_TAXTABLE(ref);
+        return (entry->i_tax_table == tt || entry->b_tax_table == tt);
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_ACCOUNT(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_entry_class_init (GncEntryClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_entry_dispose;
+    gobject_class->finalize = gnc_entry_finalize;
+    gobject_class->set_property = gnc_entry_set_property;
+    gobject_class->get_property = gnc_entry_get_property;
+
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_DESCRIPTION,
+     g_param_spec_string ("description",
+                          "Entry Description",
+                          "The description is an arbitrary string "
+                          "assigned by the user.  It provides identification "
+                          "for this entry.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncEntry *gncEntryCreate (QofBook *book)
+{
+    GncEntry *entry;
+    gnc_numeric zero = gnc_numeric_zero ();
+
+    if (!book) return NULL;
+
+    entry = g_object_new (GNC_TYPE_ENTRY, NULL);
+    qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book);
+
+    entry->desc = CACHE_INSERT ("");
+    entry->action = CACHE_INSERT ("");
+    entry->notes = CACHE_INSERT ("");
+    entry->quantity = zero;
+
+    entry->i_price = zero;
+    entry->i_taxable = TRUE;
+    entry->i_discount = zero;
+    entry->i_disc_type = GNC_AMT_TYPE_PERCENT;
+    entry->i_disc_how = GNC_DISC_PRETAX;
+
+    entry->b_price = zero;
+    entry->b_taxable = TRUE;
+    entry->billto.type = GNC_OWNER_CUSTOMER;
+    entry->b_payment = GNC_PAYMENT_CASH;
+
+    entry->values_dirty = TRUE;
+
+    qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL);
+
+    return entry;
+}
+
+void gncEntryDestroy (GncEntry *entry)
+{
+    if (!entry) return;
+    qof_instance_set_destroying(entry, TRUE);
+    gncEntryCommitEdit(entry);
+}
+
+static void gncEntryFree (GncEntry *entry)
+{
+    if (!entry) return;
+
+    qof_event_gen (&entry->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (entry->desc);
+    CACHE_REMOVE (entry->action);
+    CACHE_REMOVE (entry->notes);
+    if (entry->i_tax_values)
+        gncAccountValueDestroy (entry->i_tax_values);
+    if (entry->b_tax_values)
+        gncAccountValueDestroy (entry->b_tax_values);
+    if (entry->i_tax_table)
+        gncTaxTableDecRef (entry->i_tax_table);
+    if (entry->b_tax_table)
+        gncTaxTableDecRef (entry->b_tax_table);
+
+    /* qof_instance_release (&entry->inst); */
+    g_object_unref (entry);
+}
+
+GncEntry *
+gncCloneEntry (GncEntry *from, QofBook *book)
+{
+    /* XXX unfinished */
+    return NULL;
+}
+
+GncEntry *
+gncEntryObtainTwin (GncEntry *from, QofBook *book)
+{
+    GncEntry *entry;
+    if (!book) return NULL;
+
+    entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!entry)
+    {
+        entry = gncCloneEntry (from, book);
+    }
+
+    return entry;
+}
+
+
+/* ================================================================ */
+/* Set Functions */
+
+void gncEntrySetDate (GncEntry *entry, Timespec date)
+{
+    gboolean first_date = FALSE;
+    Timespec zero_time = { 0, 0 };
+
+    if (!entry) return;
+    if (timespec_equal (&entry->date, &date)) return;
+    if (timespec_equal (&entry->date, &zero_time))
+        first_date = TRUE;
+    gncEntryBeginEdit (entry);
+    entry->date = date;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+
+    /* Don't re-sort the first time we set the date on this entry */
+    if (!first_date)
+    {
+        if (entry->invoice)
+            gncInvoiceSortEntries(entry->invoice);
+        if (entry->bill)
+            gncInvoiceSortEntries(entry->bill);
+    }
+}
+
+void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
+{
+    if (!entry) return;
+    if (timespec_equal (&entry->date_entered, &date)) return;
+    gncEntryBeginEdit (entry);
+    entry->date_entered = date;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetDescription (GncEntry *entry, const char *desc)
+{
+    if (!entry || !desc) return;
+    SET_STR (entry, entry->desc, desc);
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetAction (GncEntry *entry, const char *action)
+{
+    if (!entry || !action) return;
+    SET_STR (entry, entry->action, action);
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetNotes (GncEntry *entry, const char *notes)
+{
+    if (!entry || !notes) return;
+    SET_STR (entry, entry->notes, notes);
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
+{
+    if (!entry) return;
+    if (gnc_numeric_eq (entry->quantity, quantity)) return;
+    gncEntryBeginEdit (entry);
+    entry->quantity = quantity;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+/* Customer Invoices */
+
+void gncEntrySetInvAccount (GncEntry *entry, Account *acc)
+{
+    if (!entry) return;
+    if (entry->i_account == acc) return;
+    gncEntryBeginEdit (entry);
+    entry->i_account = acc;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price)
+{
+    if (!entry) return;
+    if (gnc_numeric_eq (entry->i_price, price)) return;
+    gncEntryBeginEdit (entry);
+    entry->i_price = price;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable)
+{
+    if (!entry) return;
+    if (entry->i_taxable == taxable) return;
+    gncEntryBeginEdit (entry);
+    entry->i_taxable = taxable;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean taxincluded)
+{
+    if (!entry) return;
+    if (entry->i_taxincluded == taxincluded) return;
+    gncEntryBeginEdit (entry);
+    entry->i_taxincluded = taxincluded;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
+{
+    if (!entry) return;
+    if (entry->i_tax_table == table) return;
+    gncEntryBeginEdit (entry);
+    if (entry->i_tax_table)
+        gncTaxTableDecRef (entry->i_tax_table);
+    if (table)
+        gncTaxTableIncRef (table);
+    entry->i_tax_table = table;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount)
+{
+    if (!entry) return;
+    if (gnc_numeric_eq (entry->i_discount, discount)) return;
+    gncEntryBeginEdit (entry);
+    entry->i_discount = discount;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type)
+{
+    if (!entry) return;
+    if (entry->i_disc_type == type) return;
+
+    gncEntryBeginEdit (entry);
+    entry->i_disc_type = type;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how)
+{
+    if (!entry) return;
+    if (entry->i_disc_how == how) return;
+
+    gncEntryBeginEdit (entry);
+    entry->i_disc_how = how;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void qofEntrySetInvDiscType (GncEntry *entry, const char *type_string)
+{
+    GncAmountType type;
+
+    if (!entry) return;
+    gncAmountStringToType(type_string, &type);
+    if (entry->i_disc_type == type) return;
+    gncEntryBeginEdit (entry);
+    entry->i_disc_type = type;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+
+}
+
+void qofEntrySetInvDiscHow  (GncEntry *entry, const char *type)
+{
+    GncDiscountHow how;
+
+    if (!entry) return;
+    gncEntryBeginEdit (entry);
+    gncEntryDiscountStringToHow(type, &how);
+    if (entry->i_disc_how == how) return;
+    entry->i_disc_how = how;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+/* Vendor Bills */
+
+void gncEntrySetBillAccount (GncEntry *entry, Account *acc)
+{
+    if (!entry) return;
+    if (entry->b_account == acc) return;
+    gncEntryBeginEdit (entry);
+    entry->b_account = acc;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price)
+{
+    if (!entry) return;
+    if (gnc_numeric_eq (entry->b_price, price)) return;
+    gncEntryBeginEdit (entry);
+    entry->b_price = price;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable)
+{
+    if (!entry) return;
+    if (entry->b_taxable == taxable) return;
+    gncEntryBeginEdit (entry);
+    entry->b_taxable = taxable;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean taxincluded)
+{
+    if (!entry) return;
+    if (entry->b_taxincluded == taxincluded) return;
+    gncEntryBeginEdit (entry);
+    entry->b_taxincluded = taxincluded;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
+{
+    if (!entry) return;
+    if (entry->b_tax_table == table) return;
+    gncEntryBeginEdit (entry);
+    if (entry->b_tax_table)
+        gncTaxTableDecRef (entry->b_tax_table);
+    if (table)
+        gncTaxTableIncRef (table);
+    entry->b_tax_table = table;
+    entry->values_dirty = TRUE;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillable (GncEntry *entry, gboolean billable)
+{
+    if (!entry) return;
+    if (entry->billable == billable) return;
+
+    gncEntryBeginEdit (entry);
+    entry->billable = billable;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto)
+{
+    if (!entry || !billto) return;
+    if (gncOwnerEqual (&entry->billto, billto)) return;
+
+    gncEntryBeginEdit (entry);
+    gncOwnerCopy (billto, &entry->billto);
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type)
+{
+    if (!entry) return;
+    if (entry->b_payment == type) return;
+    gncEntryBeginEdit (entry);
+    entry->b_payment = type;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+/* Called from gncOrder when we're added to the Order */
+void gncEntrySetOrder (GncEntry *entry, GncOrder *order)
+{
+    if (!entry) return;
+    if (entry->order == order) return;
+    gncEntryBeginEdit (entry);
+    entry->order = order;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+
+    /* Generate an event modifying the Order's end-owner */
+#if 0
+    qof_event_gen (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
+                   QOF_EVENT_MODIFY, NULL);
+#endif
+}
+
+/* called from gncInvoice when we're added to the Invoice */
+void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice)
+{
+    if (!entry) return;
+    if (entry->invoice == invoice) return;
+    gncEntryBeginEdit (entry);
+    entry->invoice = invoice;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+/* called from gncInvoice when we're added to the Invoice/Bill */
+void gncEntrySetBill (GncEntry *entry, GncInvoice *bill)
+{
+    if (!entry) return;
+    if (entry->bill == bill) return;
+    gncEntryBeginEdit (entry);
+    entry->bill = bill;
+    mark_entry (entry);
+    gncEntryCommitEdit (entry);
+}
+
+void gncEntryCopy (const GncEntry *src, GncEntry *dest)
+{
+    if (!src || !dest) return;
+
+    gncEntryBeginEdit (dest);
+    dest->date 			= src->date;
+    dest->date_entered		= src->date_entered; /* ??? */
+    gncEntrySetDescription (dest, src->desc);
+    gncEntrySetAction (dest, src->action);
+    gncEntrySetNotes (dest, src->notes);
+    dest->quantity		= src->quantity;
+
+    dest->i_account		= src->i_account;
+    dest->i_price			= src->i_price;
+    dest->i_taxable		= src->i_taxable;
+    dest->i_taxincluded		= src->i_taxincluded;
+    dest->i_discount		= src->i_discount;
+    dest->i_disc_type		= src->i_disc_type;
+    dest->i_disc_how		= src->i_disc_how;
+
+    /* vendor bill data */
+    dest->b_account		= src->b_account;
+    dest->b_price			= src->b_price;
+    dest->b_taxable		= src->b_taxable;
+    dest->b_taxincluded		= src->b_taxincluded;
+    dest->billable		= src->billable;
+    dest->billto			= src->billto;
+
+    if (src->i_tax_table)
+        gncEntrySetInvTaxTable (dest, src->i_tax_table);
+
+    if (src->b_tax_table)
+        gncEntrySetBillTaxTable (dest, src->b_tax_table);
+
+    if (src->order)
+        gncOrderAddEntry (src->order, dest);
+
+    if (src->invoice)
+        gncInvoiceAddEntry (src->invoice, dest);
+
+    if (src->bill)
+        gncBillAddEntry (src->bill, dest);
+
+    dest->values_dirty = TRUE;
+    gncEntryCommitEdit (dest);
+}
+
+/* ================================================================ */
+/* Get Functions */
+
+Timespec gncEntryGetDate (const GncEntry *entry)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!entry) return ts;
+    return entry->date;
+}
+
+Timespec gncEntryGetDateEntered (const GncEntry *entry)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!entry) return ts;
+    return entry->date_entered;
+}
+
+const char * gncEntryGetDescription (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->desc;
+}
+
+const char * gncEntryGetAction (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->action;
+}
+
+const char * gncEntryGetNotes (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->notes;
+}
+
+gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
+{
+    if (!entry) return gnc_numeric_zero();
+    return entry->quantity;
+}
+
+/* Customer Invoice */
+
+Account * gncEntryGetInvAccount (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->i_account;
+}
+
+gnc_numeric gncEntryGetInvPrice (const GncEntry *entry)
+{
+    if (!entry) return gnc_numeric_zero();
+    return entry->i_price;
+}
+
+gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry)
+{
+    if (!entry) return gnc_numeric_zero();
+    return entry->i_discount;
+}
+
+GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
+{
+    if (!entry) return 0;
+    return entry->i_disc_type;
+}
+
+GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
+{
+    if (!entry) return 0;
+    return entry->i_disc_how;
+}
+
+char* qofEntryGetInvDiscType (const GncEntry *entry)
+{
+    char *type_string;
+
+    if (!entry) return 0;
+    type_string = g_strdup(gncAmountTypeToString(entry->i_disc_type));
+    return type_string;
+}
+
+char* qofEntryGetInvDiscHow (const GncEntry *entry)
+{
+    char *type_string;
+
+    if (!entry) return 0;
+    type_string = g_strdup(gncEntryDiscountHowToString(entry->i_disc_how));
+    return type_string;
+}
+
+gboolean gncEntryGetInvTaxable (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return entry->i_taxable;
+}
+
+gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return entry->i_taxincluded;
+}
+
+GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->i_tax_table;
+}
+
+/* vendor bills */
+
+Account * gncEntryGetBillAccount (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->b_account;
+}
+
+gnc_numeric gncEntryGetBillPrice (const GncEntry *entry)
+{
+    if (!entry) return gnc_numeric_zero();
+    return entry->b_price;
+}
+
+gboolean gncEntryGetBillTaxable (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return entry->b_taxable;
+}
+
+gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return entry->b_taxincluded;
+}
+
+GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->b_tax_table;
+}
+
+gboolean gncEntryGetBillable (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return entry->billable;
+}
+
+GncOwner * gncEntryGetBillTo (GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return &entry->billto;
+}
+
+GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry)
+{
+    if (!entry) return 0;
+    return entry->b_payment;
+}
+
+GncInvoice * gncEntryGetInvoice (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->invoice;
+}
+
+GncInvoice * gncEntryGetBill (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->bill;
+}
+
+GncOrder * gncEntryGetOrder (const GncEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->order;
+}
+
+/* ================================================================ */
+/*
+ * This is the logic of computing the total for an Entry, so you know
+ * what values to put into various Splits or to display in the ledger.
+ * In other words, we combine the quantity, unit-price, discount and
+ * taxes together, depending on various flags.
+ *
+ * There are four potental ways to combine these numbers:
+ * Discount:     Pre-Tax   Post-Tax
+ *   Tax   :     Included  Not-Included
+ *
+ * The process is relatively simple:
+ *
+ *  1) compute the agregate price (price*qty)
+ *  2) if taxincluded, then back-compute the agregate pre-tax price
+ *  3) apply discount and taxes in the appropriate order
+ *  4) return the requested results.
+ *
+ * step 2 can be done with agregate taxes; no need to compute them all
+ * unless the caller asked for the tax_value.
+ *
+ * Note that the returned "value" is such that value + tax == "total
+ * to pay," which means in the case of tax-included that the returned
+ * "value" may be less than the agregate price, even without a
+ * discount.  If you want to display the tax-included value, you need
+ * to add the value and taxes together.  In other words, the value is
+ * the amount the merchant gets; the taxes are the amount the gov't
+ * gets, and the customer pays the sum or value + taxes.
+ *
+ * The SCU is the denominator to convert the value.
+ *
+ * The discount return value is just for entertainment -- you may way
+ * to let a consumer know how much they saved.
+ */
+void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
+                           const GncTaxTable *tax_table, gboolean tax_included,
+                           gnc_numeric discount, GncAmountType discount_type,
+                           GncDiscountHow discount_how, int SCU,
+                           gnc_numeric *value, gnc_numeric *discount_value,
+                           GList **tax_value)
+{
+    gnc_numeric	aggregate;
+    gnc_numeric	pretax;
+    gnc_numeric	result;
+    gnc_numeric	tax;
+    gnc_numeric	percent = gnc_numeric_create (100, 1);
+    gnc_numeric	tpercent = gnc_numeric_zero ();
+    gnc_numeric	tvalue = gnc_numeric_zero ();
+
+    GList * 	entries = gncTaxTableGetEntries (tax_table);
+    GList * 	node;
+
+    /* Step 1: compute the aggregate price */
+
+    aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+
+    /* Step 2: compute the pre-tax aggregate */
+
+    /* First, compute the aggregate tpercent and tvalue numbers */
+    for (node = entries; node; node = node->next)
+    {
+        GncTaxTableEntry *entry = node->data;
+        gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
+
+        switch (gncTaxTableEntryGetType (entry))
+        {
+        case GNC_AMT_TYPE_VALUE:
+            tvalue = gnc_numeric_add (tvalue, amount, GNC_DENOM_AUTO,
+                                      GNC_DENOM_LCD);
+            break;
+        case GNC_AMT_TYPE_PERCENT:
+            tpercent = gnc_numeric_add (tpercent, amount, GNC_DENOM_AUTO,
+                                        GNC_DENOM_LCD);
+            break;
+        default:
+            g_warning ("Unknown tax type: %d", gncTaxTableEntryGetType (entry));
+        }
+    }
+    /* now we need to convert from 5% -> .05 */
+    tpercent = gnc_numeric_div (tpercent, percent, GNC_DENOM_AUTO,
+                                GNC_DENOM_LCD);
+
+    /* Next, actually compute the pre-tax aggregate value based on the
+     * taxincluded flag.
+     */
+    if (tax_table && tax_included)
+    {
+        /* Back-compute the pre-tax aggregate value.
+         * We know that aggregate = pretax + pretax*tpercent + tvalue, so
+         * pretax = (aggregate-tvalue)/(1+tpercent)
+         */
+        pretax = gnc_numeric_sub (aggregate, tvalue, GNC_DENOM_AUTO,
+                                  GNC_DENOM_LCD);
+        pretax = gnc_numeric_div (pretax,
+                                  gnc_numeric_add (tpercent,
+                                          gnc_numeric_create (1, 1),
+                                          GNC_DENOM_AUTO, GNC_DENOM_LCD),
+                                  GNC_DENOM_AUTO, GNC_DENOM_LCD);
+    }
+    else
+    {
+        pretax = aggregate;
+    }
+
+    /* Step 3:  apply discount and taxes in the appropriate order */
+
+    /*
+     * There are two ways to apply discounts and taxes.  In one way, you
+     * always compute the discount off the pretax number, and compute
+     * the taxes off of either the pretax value or "pretax-discount"
+     * value.  In the other way, you always compute the tax on "pretax",
+     * and compute the discount on either "pretax" or "pretax+taxes".
+     *
+     * I don't know which is the "correct" way.
+     */
+
+    /*
+     * Type:	discount	tax
+     * PRETAX	pretax		pretax-discount
+     * SAMETIME	pretax		pretax
+     * POSTTAX	pretax+tax	pretax
+     */
+
+    switch (discount_how)
+    {
+    case GNC_DISC_PRETAX:
+    case GNC_DISC_SAMETIME:
+        /* compute the discount from pretax */
+
+        if (discount_type == GNC_AMT_TYPE_PERCENT)
+        {
+            discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
+                                        GNC_DENOM_LCD);
+            discount = gnc_numeric_mul (pretax, discount, GNC_DENOM_AUTO,
+                                        GNC_DENOM_LCD);
+        }
+
+        result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+
+        /* Figure out when to apply the tax, pretax or pretax-discount */
+        if (discount_how == GNC_DISC_PRETAX)
+            pretax = result;
+        break;
+
+    case GNC_DISC_POSTTAX:
+        /* compute discount on pretax+taxes */
+
+        if (discount_type == GNC_AMT_TYPE_PERCENT)
+        {
+            gnc_numeric after_tax;
+
+            tax = gnc_numeric_mul (pretax, tpercent, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+            after_tax = gnc_numeric_add (pretax, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+            after_tax = gnc_numeric_add (after_tax, tvalue, GNC_DENOM_AUTO,
+                                         GNC_DENOM_LCD);
+            discount = gnc_numeric_div (discount, percent, GNC_DENOM_AUTO,
+                                        GNC_DENOM_LCD);
+            discount = gnc_numeric_mul (after_tax, discount, GNC_DENOM_AUTO,
+                                        GNC_DENOM_LCD);
+        }
+
+        result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+        break;
+
+    default:
+        g_warning ("unknown DiscountHow value: %d", discount_how);
+    }
+
+    /* Step 4:  return the requested results. */
+
+    /* result == amount merchant gets
+     * discount == amount of discount
+     * need to compute taxes (based on 'pretax') if the caller wants it.
+     */
+
+    if (discount_value != NULL)
+    {
+        if (SCU) discount = gnc_numeric_convert(discount, SCU, GNC_RND_ROUND);
+        *discount_value = discount;
+    }
+
+    if (value != NULL)
+    {
+        if (SCU) result = gnc_numeric_convert(result, SCU, GNC_RND_ROUND);
+        *value = result;
+    }
+
+    /* Now... Compute the list of tax values (if the caller wants it) */
+
+    if (tax_value != NULL)
+    {
+        GList *	taxes = NULL;
+
+        for (node = entries; node; node = node->next)
+        {
+            GncTaxTableEntry *entry = node->data;
+            Account *acc = gncTaxTableEntryGetAccount (entry);
+            gnc_numeric amount = gncTaxTableEntryGetAmount (entry);
+
+            g_return_if_fail (acc);
+
+            switch (gncTaxTableEntryGetType (entry))
+            {
+            case GNC_AMT_TYPE_VALUE:
+                if (SCU) amount = gnc_numeric_convert(amount, SCU, GNC_RND_ROUND);
+                taxes = gncAccountValueAdd (taxes, acc, amount);
+                break;
+            case GNC_AMT_TYPE_PERCENT:
+                amount = gnc_numeric_div (amount, percent, GNC_DENOM_AUTO,
+                                          GNC_DENOM_LCD);
+                tax = gnc_numeric_mul (pretax, amount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+                if (SCU) tax = gnc_numeric_convert(tax, SCU, GNC_RND_ROUND);
+                taxes = gncAccountValueAdd (taxes, acc, tax);
+                break;
+            default:
+                break;
+            }
+        }
+        *tax_value = taxes;
+    }
+
+    return;
+}
+
+static int
+get_entry_commodity_denom (const GncEntry *entry)
+{
+    gnc_commodity *c;
+    if (!entry)
+        return 0;
+    if (entry->invoice)
+    {
+        c = gncInvoiceGetCurrency (entry->invoice);
+        if (c)
+            return (gnc_commodity_get_fraction (c));
+    }
+    if (entry->bill)
+    {
+        c = gncInvoiceGetCurrency (entry->bill);
+        if (c)
+            return (gnc_commodity_get_fraction (c));
+    }
+    return 100000;
+}
+
+static void
+gncEntryRecomputeValues (GncEntry *entry)
+{
+    int denom;
+
+    /* See if either tax table changed since we last computed values */
+    if (entry->i_tax_table)
+    {
+        Timespec modtime = gncTaxTableLastModified (entry->i_tax_table);
+        if (timespec_cmp (&entry->i_taxtable_modtime, &modtime))
+        {
+            entry->values_dirty = TRUE;
+            entry->i_taxtable_modtime = modtime;
+        }
+    }
+    if (entry->b_tax_table)
+    {
+        Timespec modtime = gncTaxTableLastModified (entry->b_tax_table);
+        if (timespec_cmp (&entry->b_taxtable_modtime, &modtime))
+        {
+            entry->values_dirty = TRUE;
+            entry->b_taxtable_modtime = modtime;
+        }
+    }
+
+    if (!entry->values_dirty)
+        return;
+
+    /* Clear the last-computed tax values */
+    if (entry->i_tax_values)
+    {
+        gncAccountValueDestroy (entry->i_tax_values);
+        entry->i_tax_values = NULL;
+    }
+    if (entry->b_tax_values)
+    {
+        gncAccountValueDestroy (entry->b_tax_values);
+        entry->b_tax_values = NULL;
+    }
+
+    /* Determine the commodity denominator */
+    denom = get_entry_commodity_denom (entry);
+
+    /* Compute the invoice values */
+    gncEntryComputeValue (entry->quantity, entry->i_price,
+                          (entry->i_taxable ? entry->i_tax_table : NULL),
+                          entry->i_taxincluded,
+                          entry->i_discount, entry->i_disc_type,
+                          entry->i_disc_how,
+                          denom,
+                          &(entry->i_value), &(entry->i_disc_value),
+                          &(entry->i_tax_values));
+
+    /* Compute the bill values */
+    gncEntryComputeValue (entry->quantity, entry->b_price,
+                          (entry->b_taxable ? entry->b_tax_table : NULL),
+                          entry->b_taxincluded,
+                          gnc_numeric_zero(), GNC_AMT_TYPE_VALUE, GNC_DISC_PRETAX,
+                          denom,
+                          &(entry->b_value), NULL, &(entry->b_tax_values));
+
+    entry->i_value_rounded = gnc_numeric_convert (entry->i_value, denom,
+                             GNC_RND_ROUND);
+    entry->i_disc_value_rounded = gnc_numeric_convert (entry->i_disc_value, denom,
+                                  GNC_RND_ROUND);
+    entry->i_tax_value = gncAccountValueTotal (entry->i_tax_values);
+    entry->i_tax_value_rounded = gnc_numeric_convert (entry->i_tax_value, denom,
+                                 GNC_RND_ROUND);
+
+    entry->b_value_rounded = gnc_numeric_convert (entry->b_value, denom,
+                             GNC_RND_ROUND);
+    entry->b_tax_value = gncAccountValueTotal (entry->b_tax_values);
+    entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom,
+                                 GNC_RND_ROUND);
+    entry->values_dirty = FALSE;
+}
+
+void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
+                       gnc_numeric *discount_value, gnc_numeric *tax_value,
+                       GList **tax_values)
+{
+    if (!entry) return;
+    gncEntryRecomputeValues (entry);
+    if (value)
+        *value = (is_inv ? entry->i_value : entry->b_value);
+    if (discount_value)
+        *discount_value = (is_inv ? entry->i_disc_value : gnc_numeric_zero());
+    if (tax_value)
+        *tax_value = (is_inv ? entry->i_tax_value : entry->b_tax_value);
+    if (tax_values)
+        *tax_values = (is_inv ? entry->i_tax_values : entry->b_tax_values);
+}
+
+gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv)
+{
+    if (!entry) return gnc_numeric_zero();
+    gncEntryRecomputeValues (entry);
+    return (is_inv ? entry->i_value_rounded : entry->b_value_rounded);
+}
+
+gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv)
+{
+    if (!entry) return gnc_numeric_zero();
+    gncEntryRecomputeValues (entry);
+    return (is_inv ? entry->i_tax_value_rounded : entry->b_tax_value_rounded);
+}
+
+AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv)
+{
+    if (!entry) return NULL;
+    gncEntryRecomputeValues (entry);
+    return (is_inv ? entry->i_tax_values : entry->b_tax_values);
+}
+
+gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
+{
+    if (!entry) return gnc_numeric_zero();
+    gncEntryRecomputeValues (entry);
+    return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero());
+}
+
+/* XXXX this exsitnace of this routine is just wrong */
+gboolean gncEntryIsOpen (const GncEntry *entry)
+{
+    if (!entry) return FALSE;
+    return (qof_instance_get_editlevel(entry) > 0);
+}
+
+/* ================================================================ */
+
+void gncEntryBeginEdit (GncEntry *entry)
+{
+    qof_begin_edit(&entry->inst);
+}
+
+static void gncEntryOnError (QofInstance *entry, QofBackendError errcode)
+{
+    PERR("Entry QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncEntryOnDone (QofInstance *inst) {}
+
+static void entry_free (QofInstance *inst)
+{
+    GncEntry *entry = (GncEntry *)inst;
+    gncEntryFree (entry);
+}
+
+void gncEntryCommitEdit (GncEntry *entry)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(entry))) return;
+    qof_commit_edit_part2 (&entry->inst, gncEntryOnError,
+                           gncEntryOnDone, entry_free);
+}
+
+int gncEntryCompare (const GncEntry *a, const GncEntry *b)
+{
+    int compare;
+
+    if (a == b) return 0;
+    if (!a && b) return -1;
+    if (a && !b) return 1;
+
+    compare = timespec_cmp (&(a->date), &(b->date));
+    if (compare) return compare;
+
+    compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
+    if (compare) return compare;
+
+    compare = safe_strcmp (a->desc, b->desc);
+    if (compare) return compare;
+
+    compare = safe_strcmp (a->action, b->action);
+    if (compare) return compare;
+
+    return qof_instance_guid_compare(a, b);
+}
+
+#define CHECK_STRING(X, Y, FIELD) \
+    if (safe_strcmp((X)->FIELD, (Y)->FIELD) != 0) \
+    { \
+        PWARN("%s differ: %s vs %s", #FIELD, (X)->FIELD, (Y)->FIELD); \
+        return FALSE; \
+    }
+
+#define CHECK_ACCOUNT(X, Y, FIELD) \
+    if (!xaccAccountEqual((X)->FIELD, (Y)->FIELD, TRUE)) \
+    { \
+        PWARN("%s differ", #FIELD); \
+        return FALSE; \
+    }
+
+#define CHECK_NUMERIC(X, Y, FIELD) \
+    if (!gnc_numeric_equal((X)->FIELD, (Y)->FIELD)) \
+    { \
+        PWARN("%s differ", #FIELD); \
+        return FALSE; \
+    }
+
+#define CHECK_VALUE(X, Y, FIELD) \
+    if ((X)->FIELD != (Y)->FIELD) \
+    { \
+        PWARN("%s differ", #FIELD); \
+        return FALSE; \
+    }
+
+gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_ENTRY(a), FALSE);
+    g_return_val_if_fail(GNC_IS_ENTRY(b), FALSE);
+
+    CHECK_STRING(a, b, desc);
+    CHECK_STRING(a, b, action);
+    CHECK_STRING(a, b, notes);
+    CHECK_NUMERIC(a, b, quantity);
+
+    if (a->invoice != NULL)
+    {
+        CHECK_ACCOUNT(a, b, i_account);
+        CHECK_NUMERIC(a, b, i_price);
+        CHECK_VALUE(a, b, i_taxable);
+        CHECK_VALUE(a, b, i_taxincluded);
+        if (!gncTaxTableEqual(a->i_tax_table, b->i_tax_table))
+        {
+            PWARN("i_tax_table differ");
+            return FALSE;
+        }
+
+        CHECK_NUMERIC(a, b, i_discount);
+        CHECK_VALUE(a, b, i_disc_type);
+        CHECK_VALUE(a, b, i_disc_how);
+        CHECK_NUMERIC(a, b, i_value);
+        CHECK_NUMERIC(a, b, i_value_rounded);
+        CHECK_NUMERIC(a, b, i_tax_value);
+        CHECK_NUMERIC(a, b, i_tax_value_rounded);
+        CHECK_NUMERIC(a, b, i_disc_value);
+        CHECK_NUMERIC(a, b, i_disc_value_rounded);
+
+#if 0
+        Timespec	date;
+        Timespec	date_entered;
+
+        /* employee bill data */
+        GncEntryPaymentType b_payment;
+
+        /* customer invoice */
+        GList *	i_tax_values;
+        Timespec	i_taxtable_modtime;
+
+#endif
+    }
+
+    if (a->bill != NULL)
+    {
+        CHECK_ACCOUNT(a, b, b_account);
+        CHECK_NUMERIC(a, b, b_price);
+
+        CHECK_NUMERIC(a, b, b_value);
+        CHECK_NUMERIC(a, b, b_value_rounded);
+        CHECK_NUMERIC(a, b, b_tax_value);
+        CHECK_NUMERIC(a, b, b_tax_value_rounded);
+#if 0
+        Timespec	date;
+        Timespec	date_entered;
+
+        /* vendor bill data */
+        gboolean	b_taxable;
+        gboolean	b_taxincluded;
+        GncTaxTable *	b_tax_table;
+        gboolean	billable;
+        GncOwner	billto;
+
+        /* employee bill data */
+        GncEntryPaymentType b_payment;
+
+        /* vendor bill */
+        GList *	b_tax_values;
+        Timespec	b_taxtable_modtime;
+#endif
+    }
+    /* FIXME: Need real tests */
+
+    return TRUE;
+}
+
+/* ============================================================= */
+/* Object declaration */
+
+static QofObject gncEntryDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Order/Invoice/Bill Entry",
+    DI(.create            = ) (gpointer)gncEntryCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) NULL,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncEntryRegister (void)
+{
+    static QofParam params[] =
+    {
+        { ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, (QofSetterFunc)gncEntrySetDate },
+        { ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, (QofSetterFunc)gncEntrySetDateEntered },
+        { ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, (QofSetterFunc)gncEntrySetDescription },
+        { ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, (QofSetterFunc)gncEntrySetAction },
+        { ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, (QofSetterFunc)gncEntrySetNotes },
+        { ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, (QofSetterFunc)gncEntrySetQuantity },
+        { ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, (QofSetterFunc)gncEntrySetInvPrice },
+        { ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, (QofSetterFunc)gncEntrySetBillPrice },
+        { ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL },
+        { ENTRY_IACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetInvAccount,  (QofSetterFunc)gncEntrySetInvAccount  },
+        { ENTRY_BACCT, GNC_ID_ACCOUNT,  (QofAccessFunc)gncEntryGetBillAccount, (QofSetterFunc)gncEntrySetBillAccount },
+        { ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL },
+        {
+            ENTRY_INV_DISC_TYPE, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscType,
+            (QofSetterFunc)qofEntrySetInvDiscType
+        },
+        {
+            ENTRY_INV_DISC_HOW, QOF_TYPE_STRING, (QofAccessFunc)qofEntryGetInvDiscHow,
+            (QofSetterFunc)qofEntrySetInvDiscHow
+        },
+        {
+            ENTRY_INV_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
+            (QofSetterFunc)gncEntrySetInvTaxable
+        },
+        {
+            ENTRY_INV_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxIncluded,
+            (QofSetterFunc)gncEntrySetInvTaxIncluded
+        },
+        {
+            ENTRY_BILL_TAXABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetInvTaxable,
+            (QofSetterFunc)gncEntrySetInvTaxable
+        },
+        {
+            ENTRY_BILL_TAX_INC, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillTaxIncluded,
+            (QofSetterFunc)gncEntrySetBillTaxIncluded
+        },
+        { ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, (QofSetterFunc)gncEntrySetBillable },
+        { ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, (QofSetterFunc)gncEntrySetBillTo },
+        { ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
+
+    return qof_object_register (&gncEntryDesc);
+}

Copied: gnucash/trunk/src/engine/gncEntry.h (from rev 19328, gnucash/trunk/src/business/business-core/gncEntry.h)
===================================================================
--- gnucash/trunk/src/engine/gncEntry.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEntry.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,270 @@
+/********************************************************************\
+ * gncEntry.h -- the Core Business Entry Interface                  *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Entry
+    @{ */
+/** @file gncEntry.h
+    @brief  Business Entry Interface
+    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_ENTRY_H_
+#define GNC_ENTRY_H_
+
+typedef struct _gncEntry GncEntry;
+typedef struct _gncEntryClass GncEntryClass;
+
+typedef enum
+{
+    GNC_PAYMENT_CASH = 1,
+    GNC_PAYMENT_CARD
+} GncEntryPaymentType;
+
+typedef enum
+{
+    GNC_DISC_PRETAX = 1,
+    GNC_DISC_SAMETIME,
+    GNC_DISC_POSTTAX
+} GncDiscountHow;
+
+#ifdef GNUCASH_MAJOR_VERSION
+#include "gncBusiness.h"
+#endif
+#include "gncInvoice.h"
+#include "gncOrder.h"
+#include "gncTaxTable.h"
+#include "gncOwner.h"
+
+#define GNC_ID_ENTRY "gncEntry"
+
+/* --- type macros --- */
+#define GNC_TYPE_ENTRY            (gnc_entry_get_type ())
+#define GNC_ENTRY(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ENTRY, GncEntry))
+#define GNC_ENTRY_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ENTRY, GncEntryClass))
+#define GNC_IS_ENTRY(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ENTRY))
+#define GNC_IS_ENTRY_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ENTRY))
+#define GNC_ENTRY_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ENTRY, GncEntryClass))
+GType gnc_entry_get_type(void);
+
+/** How to apply the discount and taxes.  There are three distinct ways to
+ * apply them:
+ *
+ * Type:	discount	tax
+ * PRETAX	pretax		pretax-discount
+ * SAMETIME	pretax		pretax
+ * POSTTAX	pretax+tax	pretax
+ */
+
+const char * gncEntryDiscountHowToString (GncDiscountHow how);
+gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how);
+
+const char * gncEntryPaymentTypeToString (GncEntryPaymentType type);
+gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type);
+
+/** @name Create/Destroy Functions
+ @{ */
+GncEntry *gncEntryCreate (QofBook *book);
+void gncEntryDestroy (GncEntry *entry);
+/** @} */
+
+/* SET FUNCTIONS */
+
+/** @name Generic (shared) data
+ @{ */
+void gncEntrySetDate (GncEntry *entry, Timespec date);
+void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
+void gncEntrySetDescription (GncEntry *entry, const char *desc);
+void gncEntrySetAction (GncEntry *entry, const char *action);
+void gncEntrySetNotes (GncEntry *entry, const char *notes);
+void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
+/** @} */
+
+/** @name Customer Invoices
+ @{ */
+void gncEntrySetInvAccount (GncEntry *entry, Account *acc);
+void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price);
+void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable);
+void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean tax_included);
+void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table);
+void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount);
+void gncEntrySetInvDiscountType (GncEntry *entry, GncAmountType type);
+void gncEntrySetInvDiscountHow (GncEntry *entry, GncDiscountHow how);
+void qofEntrySetInvDiscType (GncEntry *entry, const char *type);
+void qofEntrySetInvDiscHow  (GncEntry *entry, const char *type);
+/** @} */
+
+/** @name Vendor Bills (and Employee Expenses)
+ @{ */
+void gncEntrySetBillAccount (GncEntry *entry, Account *acc);
+void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price);
+void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable);
+void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean tax_included);
+void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table);
+void gncEntrySetBillable (GncEntry *entry, gboolean billable);
+void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto);
+/** @} */
+
+/** @name employee-stuff
+ @{ */
+void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type);
+/** @} */
+
+/* GET FUNCTIONS */
+/** @name Generic (shared) data
+ @{ */
+Timespec gncEntryGetDate (const GncEntry *entry);
+Timespec gncEntryGetDateEntered (const GncEntry *entry);
+const char * gncEntryGetDescription (const GncEntry *entry);
+const char * gncEntryGetAction (const GncEntry *entry);
+const char * gncEntryGetNotes (const GncEntry *notes);
+gnc_numeric gncEntryGetQuantity (const GncEntry *entry);
+/** @} */
+
+/** @name Customer Invoices
+ @{ */
+Account * gncEntryGetInvAccount (const GncEntry *entry);
+gnc_numeric gncEntryGetInvPrice (const GncEntry *entry);
+gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry);
+GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry);
+GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry);
+char* qofEntryGetInvDiscType (const GncEntry *entry);
+char* qofEntryGetInvDiscHow (const GncEntry *entry);
+gboolean gncEntryGetInvTaxable (const GncEntry *entry);
+gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry);
+GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry);
+/** @} */
+
+/** @name Vendor Bills (and Employee Expenses)
+ @{ */
+Account * gncEntryGetBillAccount (const GncEntry *entry);
+gnc_numeric gncEntryGetBillPrice (const GncEntry *entry);
+gboolean gncEntryGetBillTaxable (const GncEntry *entry);
+gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry);
+GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry);
+gboolean gncEntryGetBillable (const GncEntry *entry);
+GncOwner *gncEntryGetBillTo (GncEntry *entry);
+
+GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry);
+/** @} */
+
+void gncEntryCopy (const GncEntry *src, GncEntry *dest);
+
+/** @name Getting Values
+
+ * The first three return the rounded values -- the last returns the
+ * list of unrounded account-values.  The list belongs to the entry
+ * and will be destroyed, so use it quickly.
+ @{
+*/
+gnc_numeric gncEntryReturnValue (GncEntry *entry, gboolean is_inv);
+gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv);
+gnc_numeric gncEntryReturnTaxValue (GncEntry *entry, gboolean is_inv);
+typedef GList AccountValueList;
+AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv);
+
+/** Compute the Entry value, tax-value, and discount_value, based on
+ * the quantity, price, discount, tax-table, and types.  The value is
+ * the amount the merchant gets, the taxes are what the gov't gets,
+ * and the discount is how much the customer saved.  The SCU is the
+ * target denominator of the value and tax -- it should be the
+ * account or commodity SCU of the target.
+ *
+ * The tax_values list is the property of the entry and will be
+ * destroyed automatically, so use it quickly.  Note that all return
+ * values from these two functions are NOT rounded.
+ */
+void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
+                       gnc_numeric *discount, gnc_numeric *tax_value,
+                       GList **tax_values);
+
+void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
+                           const GncTaxTable *tax_table, gboolean tax_included,
+                           gnc_numeric discount, GncAmountType discount_type,
+                           GncDiscountHow discount_how, int SCU,
+                           /* return values */
+                           gnc_numeric *value, gnc_numeric *discount_value,
+                           GList **tax_values);
+
+/** @} */
+
+GncOrder * gncEntryGetOrder (const GncEntry *entry);
+GncInvoice * gncEntryGetInvoice (const GncEntry *entry);
+GncInvoice * gncEntryGetBill (const GncEntry *entry);
+
+/** Return a pointer to the instance gncEntry that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncEntry * gncEntryLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncEntry * gncEntryLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ENTRY, GncEntry);
+}
+
+gboolean gncEntryIsOpen (const GncEntry *entry);
+void gncEntryBeginEdit (GncEntry *entry);
+void gncEntryCommitEdit (GncEntry *entry);
+int gncEntryCompare (const GncEntry *a, const GncEntry *b);
+gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b);
+
+#define ENTRY_DATE			"date"
+#define ENTRY_DATE_ENTERED 	"date-entered"
+#define ENTRY_DESC			"desc"
+#define ENTRY_ACTION		"action"
+#define ENTRY_NOTES			"notes"
+#define ENTRY_QTY			"qty"
+
+#define ENTRY_IPRICE		"iprice"
+#define ENTRY_IACCT			"invoice-account"
+#define ENTRY_BACCT			"bill-account"
+#define ENTRY_BPRICE		"bprice"
+#define ENTRY_BILLABLE		"billable?"
+#define ENTRY_BILLTO		"bill-to"
+
+#define ENTRY_ORDER			"order"
+#define ENTRY_INVOICE		"invoice"
+#define ENTRY_BILL			"bill"
+
+#define ENTRY_INV_DISC_TYPE		"discount-type"
+#define ENTRY_INV_DISC_HOW		"discount-method"
+
+#define ENTRY_INV_TAXABLE	"invoice-taxable"
+#define ENTRY_BILL_TAXABLE	"bill-taxable"
+#define ENTRY_INV_TAX_INC	"invoice-tax-included"
+#define ENTRY_BILL_TAX_INC	"bill-tax-included"
+#define ENTRY_INV_DISCOUNT	"invoice-discount"
+#define ENTRY_BILL_PAY_TYPE "bill-payment-type"
+
+
+/* deprecated functions, should be removed */
+#define gncEntryGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+
+#endif /* GNC_ENTRY_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncEntryP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncEntryP.h)
===================================================================
--- gnucash/trunk/src/engine/gncEntryP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncEntryP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,64 @@
+/********************************************************************\
+ * gncEntryP.h -- the Core Busines Entry Interface                  *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_ENTRYP_H_
+#define GNC_ENTRYP_H_
+
+#include "gncEntry.h"
+
+gboolean gncEntryRegister (void);
+void gncEntrySetGUID (GncEntry *entry, const GncGUID *guid);
+void gncEntrySetOrder (GncEntry *entry, GncOrder *order);
+void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice);
+void gncEntrySetBill (GncEntry *entry, GncInvoice *bill);
+void gncEntrySetDirty (GncEntry *entry, gboolean dirty);
+
+
+/** The gncCloneEntry() routine makes a copy of the indicated
+ *  entry, placing it in the indicated book.  It copies
+ *  the whole kit-n-kaboodle.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncEntry * gncCloneEntry (GncEntry *from, QofBook *);
+
+/** The gncEntryObtainTwin() will find the 'twin' of the
+ *  indicated entry in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneEntry()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book);
+
+#define gncEntrySetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+#endif /* GNC_ENTRYP_H_ */

Copied: gnucash/trunk/src/engine/gncInvoice.c (from rev 19328, gnucash/trunk/src/business/business-core/gncInvoice.c)
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncInvoice.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,2129 @@
+/********************************************************************\
+ * gncInvoice.c -- the Core Business Invoice                        *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001,2002,2006 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "Transaction.h"
+#include "Account.h"
+#include "gncBillTermP.h"
+#include "gncEntry.h"
+#include "gncEntryP.h"
+#include "gncJobP.h"
+#include "gncInvoice.h"
+#include "gncInvoiceP.h"
+#include "gncOwnerP.h"
+
+struct _gncInvoice
+{
+    QofInstance inst;
+
+    char        *id;
+    char        *notes;
+    gboolean    active;
+
+    char        *billing_id;
+    char        *printname;
+    GncBillTerm *terms;
+    GList       *entries;
+    GList       *prices;
+    GncOwner    owner;
+    GncOwner    billto;
+    GncJob      *job;
+    Timespec    date_opened;
+    Timespec    date_posted;
+
+    gnc_numeric	to_charge_amount;
+
+    gnc_commodity * currency;
+
+    Account     *posted_acc;
+    Transaction *posted_txn;
+    GNCLot      *posted_lot;
+};
+
+struct _gncInvoiceClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME	GNC_ID_INVOICE
+
+#define GNC_INVOICE_ID		"gncInvoice"
+#define GNC_INVOICE_GUID	"invoice-guid"
+
+#define SET_STR(obj, member, str) { \
+	char * tmp; \
+	\
+	if (!safe_strcmp (member, str)) return; \
+	gncInvoiceBeginEdit (obj); \
+	tmp = CACHE_INSERT (str); \
+	CACHE_REMOVE (member); \
+	member = tmp; \
+	}
+
+static void mark_invoice (GncInvoice *invoice);
+static void
+mark_invoice (GncInvoice *invoice)
+{
+    qof_instance_set_dirty(&invoice->inst);
+    qof_event_gen (&invoice->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+QofBook * gncInvoiceGetBook(GncInvoice *x)
+{
+    return qof_instance_get_book(QOF_INSTANCE(x));
+}
+
+/* ================================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NOTES
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncInvoice, gnc_invoice, QOF_TYPE_INSTANCE);
+
+static void
+gnc_invoice_init(GncInvoice* inv)
+{
+}
+
+static void
+gnc_invoice_dispose(GObject *invp)
+{
+    G_OBJECT_CLASS(gnc_invoice_parent_class)->dispose(invp);
+}
+
+static void
+gnc_invoice_finalize(GObject* invp)
+{
+    G_OBJECT_CLASS(gnc_invoice_parent_class)->finalize(invp);
+}
+
+static void
+gnc_invoice_get_property (GObject         *object,
+                          guint            prop_id,
+                          GValue          *value,
+                          GParamSpec      *pspec)
+{
+    GncInvoice *inv;
+
+    g_return_if_fail(GNC_IS_INVOICE(object));
+
+    inv = GNC_INVOICE(object);
+    switch (prop_id)
+    {
+    case PROP_NOTES:
+        g_value_set_string(value, inv->notes);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_invoice_set_property (GObject         *object,
+                          guint            prop_id,
+                          const GValue          *value,
+                          GParamSpec      *pspec)
+{
+    GncInvoice *inv;
+
+    g_return_if_fail(GNC_IS_INVOICE(object));
+
+    inv = GNC_INVOICE(object);
+    switch (prop_id)
+    {
+    case PROP_NOTES:
+        gncInvoiceSetNotes(inv, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Returns a string representing this object */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncInvoice* inv;
+    QofInstance* owner;
+    gchar* s;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
+
+    inv = GNC_INVOICE(inst);
+    owner = qofOwnerGetOwner(&inv->owner);
+    if (owner != NULL)
+    {
+        gchar* display_name;
+
+        display_name = qof_instance_get_display_name(owner);
+        s = g_strdup_printf("Invoice %s (%s)", inv->id, display_name);
+        g_free(display_name);
+    }
+    else
+    {
+        s = g_strdup_printf("Invoice %s", inv->id);
+    }
+
+    return s;
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncInvoice* inv;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
+
+    inv = GNC_INVOICE(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (inv->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_JOB(ref))
+    {
+        return (inv->job == GNC_JOB(ref));
+    }
+    else if (GNC_IS_COMMODITY(ref))
+    {
+        return (inv->currency == GNC_COMMODITY(ref));
+    }
+    else if (GNC_IS_ACCOUNT(ref))
+    {
+        return (inv->posted_acc == GNC_ACCOUNT(ref));
+    }
+    else if (GNC_IS_TRANSACTION(ref))
+    {
+        return (inv->posted_txn == GNC_TRANSACTION(ref));
+    }
+    else if (GNC_IS_LOT(ref))
+    {
+        return (inv->posted_lot == GNC_LOT(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_JOB(ref) && !GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref)
+            && !GNC_IS_TRANSACTION(ref) && !GNC_IS_LOT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_invoice_class_init (GncInvoiceClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_invoice_dispose;
+    gobject_class->finalize = gnc_invoice_finalize;
+    gobject_class->set_property = gnc_invoice_set_property;
+    gobject_class->get_property = gnc_invoice_get_property;
+
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NOTES,
+     g_param_spec_string ("notes",
+                          "Invoice Notes",
+                          "The invoice notes is an arbitrary string "
+                          "assigned by the user to provide notes regarding "
+                          "this invoice.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncInvoice *gncInvoiceCreate (QofBook *book)
+{
+    GncInvoice *invoice;
+
+    if (!book) return NULL;
+
+    invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
+    qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
+
+    invoice->id = CACHE_INSERT ("");
+    invoice->notes = CACHE_INSERT ("");
+    invoice->billing_id = CACHE_INSERT ("");
+
+    invoice->billto.type = GNC_OWNER_CUSTOMER;
+    invoice->active = TRUE;
+
+    invoice->to_charge_amount = gnc_numeric_zero();
+
+    qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
+
+    return invoice;
+}
+
+void gncInvoiceDestroy (GncInvoice *invoice)
+{
+    if (!invoice) return;
+    qof_instance_set_destroying(invoice, TRUE);
+    gncInvoiceCommitEdit (invoice);
+}
+
+static void gncInvoiceFree (GncInvoice *invoice)
+{
+    if (!invoice) return;
+
+    qof_event_gen (&invoice->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (invoice->id);
+    CACHE_REMOVE (invoice->notes);
+    CACHE_REMOVE (invoice->billing_id);
+    g_list_free (invoice->entries);
+    g_list_free (invoice->prices);
+
+    if (invoice->printname) g_free (invoice->printname);
+
+    if (invoice->terms)
+        gncBillTermDecRef (invoice->terms);
+
+    /* qof_instance_release (&invoice->inst); */
+    g_object_unref (invoice);
+}
+
+GncInvoice *
+gncCloneInvoice (GncInvoice *from, QofBook *book)
+{
+    GList *node;
+    GncInvoice *invoice;
+
+    if (!book) return NULL;
+
+    invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
+    qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
+
+    invoice->id = CACHE_INSERT (from->id);
+    invoice->notes = CACHE_INSERT (from->notes);
+    invoice->billing_id = CACHE_INSERT (from->billing_id);
+    invoice->active = from->active;
+
+    invoice->billto = gncCloneOwner (&from->billto, book);
+    invoice->owner = gncCloneOwner (&from->owner, book);
+    invoice->job = (GncJob*)gncJobObtainTwin (from->job, book);
+    invoice->terms = gncBillTermObtainTwin (from->terms, book);
+    gncBillTermIncRef (invoice->terms);
+
+
+    invoice->to_charge_amount = from->to_charge_amount;
+    invoice->printname = NULL; /* that's right, NULL. See below. */
+    invoice->date_opened = from->date_opened;
+    invoice->date_posted = from->date_posted;
+
+    invoice->currency = gnc_commodity_obtain_twin (from->currency, book);
+
+    invoice->entries = NULL;
+    for (node = g_list_last(from->entries); node; node = node->next)
+    {
+        GncEntry *entry = node->data;
+        entry = gncEntryObtainTwin (entry, book);
+        invoice->entries = g_list_prepend (invoice->entries, entry);
+    }
+
+    invoice->prices = NULL;
+    for (node = g_list_last(from->prices); node; node = node->next)
+    {
+        GNCPrice *price = node->data;
+        price = gnc_price_clone(price, book);
+        invoice->prices = g_list_prepend (invoice->prices, price);
+    }
+
+    /* XXX should probably be obtain-twin not lookup-twin */
+    invoice->posted_acc =
+        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->posted_acc), book));
+#if 0
+    XXX not done * /
+    Transaction * posted_txn;
+    GNCLot *	posted_lot;
+#endif
+
+    qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
+
+    return invoice;
+}
+
+GncInvoice *
+gncInvoiceObtainTwin (GncInvoice *from, QofBook *book)
+{
+    GncInvoice *invoice;
+    if (!book) return NULL;
+
+    invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!invoice)
+    {
+        invoice = gncCloneInvoice (from, book);
+    }
+
+    return invoice;
+}
+
+/* ================================================================== */
+/* Set Functions */
+
+void gncInvoiceSetID (GncInvoice *invoice, const char *id)
+{
+    if (!invoice || !id) return;
+    SET_STR (invoice, invoice->id, id);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner)
+{
+    if (!invoice || !owner) return;
+    if (gncOwnerEqual (&invoice->owner, owner)) return;
+    gncInvoiceBeginEdit (invoice);
+    gncOwnerCopy (owner, &invoice->owner);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+static void
+qofInvoiceSetOwner (GncInvoice *invoice, QofInstance *ent)
+{
+    if (!invoice || !ent)
+    {
+        return;
+    }
+    gncInvoiceBeginEdit (invoice);
+    qofOwnerSetEntity(&invoice->owner, ent);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+static void
+qofInvoiceSetBillTo (GncInvoice *invoice, QofInstance *ent)
+{
+    if (!invoice || !ent)
+    {
+        return;
+    }
+    gncInvoiceBeginEdit (invoice);
+    qofOwnerSetEntity(&invoice->billto, ent);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date)
+{
+    if (!invoice) return;
+    if (timespec_equal (&invoice->date_opened, &date)) return;
+    gncInvoiceBeginEdit (invoice);
+    invoice->date_opened = date;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date)
+{
+    if (!invoice) return;
+    if (timespec_equal (&invoice->date_posted, &date)) return;
+    gncInvoiceBeginEdit (invoice);
+    invoice->date_posted = date;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms)
+{
+    if (!invoice) return;
+    if (invoice->terms == terms) return;
+    gncInvoiceBeginEdit (invoice);
+    if (invoice->terms)
+        gncBillTermDecRef (invoice->terms);
+    invoice->terms = terms;
+    if (invoice->terms)
+        gncBillTermIncRef (invoice->terms);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id)
+{
+    if (!invoice) return;
+    SET_STR (invoice, invoice->billing_id, billing_id);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes)
+{
+    if (!invoice || !notes) return;
+    SET_STR (invoice, invoice->notes, notes);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
+{
+    if (!invoice) return;
+    if (invoice->active == active) return;
+    gncInvoiceBeginEdit (invoice);
+    invoice->active = active;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
+{
+    if (!invoice || !currency) return;
+    if (invoice->currency &&
+            gnc_commodity_equal (invoice->currency, currency))
+        return;
+    gncInvoiceBeginEdit (invoice);
+    invoice->currency = currency;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto)
+{
+    if (!invoice || !billto) return;
+    if (gncOwnerEqual (&invoice->billto, billto)) return;
+
+    gncInvoiceBeginEdit (invoice);
+    gncOwnerCopy (billto, &invoice->billto);
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount)
+{
+    if (!invoice) return;
+    if (gnc_numeric_equal (invoice->to_charge_amount, amount)) return;
+    gncInvoiceBeginEdit (invoice);
+    invoice->to_charge_amount = amount;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
+{
+    if (!invoice) return;
+    g_return_if_fail (invoice->posted_txn == NULL);
+
+    gncInvoiceBeginEdit (invoice);
+    invoice->posted_txn = txn;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot)
+{
+    if (!invoice) return;
+    g_return_if_fail (invoice->posted_lot == NULL);
+
+    gncInvoiceBeginEdit (invoice);
+    invoice->posted_lot = lot;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc)
+{
+    if (!invoice) return;
+    g_return_if_fail (invoice->posted_acc == NULL);
+
+    gncInvoiceBeginEdit (invoice);
+    invoice->posted_acc = acc;
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+}
+
+void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
+{
+    GncInvoice *old;
+
+    if (!invoice || !entry) return;
+
+    old = gncEntryGetInvoice (entry);
+    if (old == invoice) return;	/* I already own this one */
+    if (old) gncInvoiceRemoveEntry (old, entry);
+
+    gncEntrySetInvoice (entry, invoice);
+    invoice->entries = g_list_insert_sorted (invoice->entries, entry,
+                       (GCompareFunc)gncEntryCompare);
+    mark_invoice (invoice);
+}
+
+void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
+{
+    if (!invoice || !entry) return;
+
+    gncEntrySetInvoice (entry, NULL);
+    invoice->entries = g_list_remove (invoice->entries, entry);
+    mark_invoice (invoice);
+}
+
+void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
+{
+    if (!invoice || !price) return;
+
+    invoice->prices = g_list_prepend(invoice->prices, price);
+    mark_invoice (invoice);
+}
+
+void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price)
+{
+    if (!invoice || !price) return;
+
+    invoice->prices = g_list_remove (invoice->prices, price);
+    mark_invoice (invoice);
+}
+
+void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
+{
+    GncInvoice *old;
+
+    if (!bill || !entry) return;
+
+    old = gncEntryGetBill (entry);
+    if (old == bill) return;	/* I already own this one */
+    if (old) gncBillRemoveEntry (old, entry);
+
+    gncEntrySetBill (entry, bill);
+    bill->entries = g_list_insert_sorted (bill->entries, entry,
+                                          (GCompareFunc)gncEntryCompare);
+    mark_invoice (bill);
+}
+
+void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
+{
+    if (!bill || !entry) return;
+
+    gncEntrySetBill (entry, NULL);
+    bill->entries = g_list_remove (bill->entries, entry);
+    mark_invoice (bill);
+}
+
+void gncBillAddPrice (GncInvoice *bill, GNCPrice *price)
+{
+    if (!bill || !price) return;
+
+    bill->prices = g_list_prepend(bill->prices, price);
+    mark_invoice (bill);
+}
+
+void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price)
+{
+    if (!bill || !price) return;
+
+    bill->prices = g_list_remove (bill->prices, price);
+    mark_invoice (bill);
+}
+
+
+void gncInvoiceSortEntries (GncInvoice *invoice)
+{
+    if (!invoice) return;
+    invoice->entries = g_list_sort(invoice->entries,
+                                   (GCompareFunc)gncEntryCompare);
+    mark_invoice(invoice);
+}
+
+/* ================================================================== */
+/* Get Functions */
+
+const char * gncInvoiceGetID (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->id;
+}
+
+GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return &invoice->owner;
+}
+
+static QofInstance*
+qofInvoiceGetOwner (GncInvoice *invoice)
+{
+    GncOwner *owner;
+
+    if (!invoice)
+    {
+        return NULL;
+    }
+    owner = &invoice->owner;
+    return QOF_INSTANCE(owner);
+}
+
+static QofInstance*
+qofInvoiceGetBillTo (GncInvoice *invoice)
+{
+    GncOwner *billto;
+
+    if (!invoice)
+    {
+        return NULL;
+    }
+    billto = &invoice->billto;
+    return QOF_INSTANCE(billto);
+}
+
+Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!invoice) return ts;
+    return invoice->date_opened;
+}
+
+Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!invoice) return ts;
+    return invoice->date_posted;
+}
+
+Timespec gncInvoiceGetDateDue (const GncInvoice *invoice)
+{
+    Transaction *txn;
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!invoice) return ts;
+    txn = gncInvoiceGetPostedTxn (invoice);
+    if (!txn) return ts;
+    return xaccTransRetDateDueTS (txn);
+}
+
+GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->terms;
+}
+
+const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->billing_id;
+}
+
+const char * gncInvoiceGetNotes (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->notes;
+}
+
+GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice)
+{
+    GncOwner *owner;
+    g_return_val_if_fail (invoice, GNC_OWNER_NONE);
+
+    owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
+    return (gncOwnerGetType (owner));
+}
+
+static gnc_numeric
+gncInvoiceGetTotalInternal (GncInvoice *invoice, gboolean use_value,
+                            gboolean use_tax,
+                            gboolean use_payment_type, GncEntryPaymentType type)
+{
+    GList *node;
+    gnc_numeric total = gnc_numeric_zero();
+    gboolean reverse;
+
+    g_return_val_if_fail (invoice, total);
+
+    reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
+
+    for (node = gncInvoiceGetEntries(invoice); node; node = node->next)
+    {
+        GncEntry *entry = node->data;
+        gnc_numeric value, tax;
+
+        if (use_payment_type && gncEntryGetBillPayment (entry) != type)
+            continue;
+
+        gncEntryGetValue (entry, reverse, &value, NULL, &tax, NULL);
+
+        if (gnc_numeric_check (value) == GNC_ERROR_OK)
+        {
+            if (use_value)
+                total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+        }
+        else
+            g_warning ("bad value in our entry");
+
+        if (gnc_numeric_check (tax) == GNC_ERROR_OK)
+        {
+            if (use_tax)
+                total = gnc_numeric_add (total, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+        }
+        else
+            g_warning ("bad tax-value in our entry");
+    }
+    return total;
+}
+
+gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice)
+{
+    if (!invoice) return gnc_numeric_zero();
+    return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, FALSE, 0);
+}
+
+gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice)
+{
+    if (!invoice) return gnc_numeric_zero();
+    return gncInvoiceGetTotalInternal(invoice, TRUE, FALSE, FALSE, 0);
+}
+
+gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice)
+{
+    if (!invoice) return gnc_numeric_zero();
+    return gncInvoiceGetTotalInternal(invoice, FALSE, TRUE, FALSE, 0);
+}
+
+gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type)
+{
+    if (!invoice) return gnc_numeric_zero();
+    return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
+}
+
+const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type)
+{
+    switch (type)
+    {
+    case GNC_OWNER_CUSTOMER:
+        return _("Invoice");
+    case GNC_OWNER_VENDOR:
+        return _("Bill");
+    case GNC_OWNER_EMPLOYEE:
+        return _("Expense");
+    default:
+        return NULL;
+    }
+
+}
+
+const char * gncInvoiceGetType (GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return gncInvoiceGetTypeFromOwnerType (gncInvoiceGetOwnerType (invoice));
+}
+
+gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->currency;
+}
+
+GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return &invoice->billto;
+}
+
+GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->posted_lot;
+}
+
+Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->posted_txn;
+}
+
+Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->posted_acc;
+}
+
+gboolean gncInvoiceGetActive (const GncInvoice *invoice)
+{
+    if (!invoice) return FALSE;
+    return invoice->active;
+}
+
+
+gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
+{
+    if (!invoice) return gnc_numeric_zero();
+    return invoice->to_charge_amount;
+}
+
+EntryList * gncInvoiceGetEntries (GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->entries;
+}
+
+GList * gncInvoiceGetPrices(GncInvoice *invoice)
+{
+    if (!invoice) return NULL;
+    return invoice->prices;
+}
+
+GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity *commodity)
+{
+    GList *node = g_list_first(invoice->prices);
+
+    while (node != NULL)
+    {
+        GNCPrice *curr = (GNCPrice*)node->data;
+
+        if (gnc_commodity_equal(commodity, gnc_price_get_commodity(curr)))
+            return curr;
+
+        node = g_list_next(node);
+    }
+
+    return NULL;
+}
+
+static QofCollection*
+qofInvoiceGetEntries (GncInvoice *invoice)
+{
+    QofCollection *entry_coll;
+    GList         *list;
+    QofInstance     *entry;
+
+    entry_coll = qof_collection_new(GNC_ID_ENTRY);
+    for (list = gncInvoiceGetEntries(invoice); list != NULL; list = list->next)
+    {
+        entry = QOF_INSTANCE(list->data);
+        qof_collection_add_entity(entry_coll, entry);
+    }
+    return entry_coll;
+}
+
+static void
+qofInvoiceEntryCB (QofInstance *ent, gpointer user_data)
+{
+    GncInvoice *invoice;
+
+    invoice = (GncInvoice*)user_data;
+    if (!invoice || !ent)
+    {
+        return;
+    }
+    switch (gncInvoiceGetOwnerType (invoice))
+    {
+    case GNC_OWNER_VENDOR:
+    {
+        gncBillAddEntry (invoice, (GncEntry*) ent);
+        break;
+    }
+    default :
+    {
+        gncInvoiceAddEntry(invoice, (GncEntry*)ent);
+        break;
+    }
+    }
+}
+
+static void
+qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll)
+{
+    if (!entry_coll)
+    {
+        return;
+    }
+    if (0 == safe_strcmp(qof_collection_get_type(entry_coll), GNC_ID_ENTRY))
+    {
+        qof_collection_foreach(entry_coll, qofInvoiceEntryCB, invoice);
+    }
+}
+
+static GncJob*
+qofInvoiceGetJob (const GncInvoice *invoice)
+{
+    if (!invoice)
+    {
+        return NULL;
+    }
+    return invoice->job;
+}
+
+static void
+qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
+{
+    if (!invoice)
+    {
+        return;
+    }
+    invoice->job = job;
+}
+
+static void
+gncInvoiceDetachFromLot (GNCLot *lot)
+{
+    KvpFrame *kvp;
+
+    if (!lot) return;
+
+    kvp = gnc_lot_get_slots (lot);
+    kvp_frame_set_slot_path (kvp, NULL, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+}
+
+static void
+gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+
+    if (!invoice || !lot)
+        return;
+
+    if (invoice->posted_lot) return;	/* Cannot reset invoice's lot */
+
+    kvp = gnc_lot_get_slots (lot);
+    value = kvp_value_new_guid (qof_instance_get_guid (QOF_INSTANCE(invoice)));
+    kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+    kvp_value_delete (value);
+    gncInvoiceSetPostedLot (invoice, lot);
+}
+
+GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+    GncGUID *guid;
+    QofBook *book;
+
+    if (!lot) return NULL;
+
+    book = gnc_lot_get_book (lot);
+    kvp = gnc_lot_get_slots (lot);
+    value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+    if (!value) return NULL;
+
+    guid = kvp_value_get_guid (value);
+    return gncInvoiceLookup(book, guid);
+}
+
+static void
+gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+
+    if (!invoice || !txn)
+        return;
+
+    if (invoice->posted_txn) return;	/* Cannot reset invoice's txn */
+
+    xaccTransBeginEdit (txn);
+    kvp = xaccTransGetSlots (txn);
+    value = kvp_value_new_guid (qof_instance_get_guid(QOF_INSTANCE(invoice)));
+    kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+    kvp_value_delete (value);
+    xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
+    xaccTransCommitEdit (txn);
+    gncInvoiceSetPostedTxn (invoice, txn);
+}
+
+GncInvoice *
+gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+    GncGUID *guid;
+    QofBook *book;
+
+    if (!txn) return NULL;
+
+    book = xaccTransGetBook (txn);
+    kvp = xaccTransGetSlots (txn);
+    value = kvp_frame_get_slot_path (kvp, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+    if (!value) return NULL;
+
+    guid = kvp_value_get_guid (value);
+    return gncInvoiceLookup(book, guid);
+}
+
+struct lotmatch
+{
+    GncOwner *owner;
+    gboolean reverse;
+};
+
+static gboolean
+gnc_lot_match_owner_payment (GNCLot *lot, gpointer user_data)
+{
+    struct lotmatch *lm = user_data;
+    GncOwner owner_def, *owner;
+    gnc_numeric balance = gnc_lot_get_balance (lot);
+
+    /* Is this a payment lot */
+    if (gnc_numeric_positive_p (lm->reverse ? balance :
+                                gnc_numeric_neg (balance)))
+        return FALSE;
+
+    /* Is there an invoice attached? */
+    if (gncInvoiceGetInvoiceFromLot (lot))
+        return FALSE;
+
+    /* Is it ours? */
+    if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
+        return FALSE;
+    owner = gncOwnerGetEndOwner (&owner_def);
+
+    return gncOwnerEqual (owner, lm->owner);
+}
+
+Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
+                                       Timespec *post_date, Timespec *due_date,
+                                       const char * memo, gboolean accumulatesplits)
+{
+    Transaction *txn;
+    QofBook *book;
+    GNCLot *lot = NULL;
+    GList *iter;
+    GList *splitinfo = NULL;
+    gnc_numeric total;
+    gboolean reverse;
+    const char *name, *type;
+    char *lot_title;
+    Account *ccard_acct = NULL;
+    GncOwner *owner;
+
+    if (!invoice || !acc) return NULL;
+
+    gncInvoiceBeginEdit (invoice);
+    book = qof_instance_get_book(invoice);
+
+    /* Stabilize the Billing Terms of this invoice */
+    if (invoice->terms)
+        gncInvoiceSetTerms (invoice,
+                            gncBillTermReturnChild (invoice->terms, TRUE));
+
+    /* Figure out if we need to "reverse" the numbers. */
+    reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
+
+    /* Figure out if we need to separate out "credit-card" items */
+    owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
+    if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)
+        ccard_acct = gncEmployeeGetCCard (gncOwnerGetEmployee (owner));
+
+    /* Find an existing payment-lot for this owner */
+    {
+        LotList *lot_list;
+        struct lotmatch lm;
+
+        lm.reverse = reverse;
+        lm.owner = owner;
+
+        lot_list = xaccAccountFindOpenLots (acc, gnc_lot_match_owner_payment,
+                                            &lm, NULL);
+        if (lot_list)
+            lot = lot_list->data;
+
+        g_list_free (lot_list);
+    }
+
+    /* Create a new lot for this invoice, if we need to do so */
+    if (!lot)
+        lot = gnc_lot_new (book);
+    gnc_lot_begin_edit (lot);
+
+    type = gncInvoiceGetType (invoice);
+
+    /* Set the lot title */
+    lot_title = g_strdup_printf ("%s %s", type, gncInvoiceGetID (invoice));
+    gnc_lot_set_title (lot, lot_title);
+    g_free (lot_title);
+
+    /* Create a new transaction */
+    txn = xaccMallocTransaction (book);
+    xaccTransBeginEdit (txn);
+
+    name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
+
+    /* Set Transaction Description (Owner Name) , Num (invoice ID), Currency */
+    xaccTransSetDescription (txn, name ? name : "");
+    xaccTransSetNum (txn, gncInvoiceGetID (invoice));
+    xaccTransSetCurrency (txn, invoice->currency);
+
+    /* Entered and Posted at date */
+    xaccTransSetDateEnteredSecs (txn, time(NULL));
+    if (post_date)
+    {
+        xaccTransSetDatePostedTS (txn, post_date);
+        gncInvoiceSetDatePosted (invoice, *post_date);
+    }
+
+    if (due_date)
+        xaccTransSetDateDueTS (txn, due_date);
+
+    /* Iterate through the entries; sum up everything for each account.
+     * then create the appropriate splits in this txn.
+     */
+    total = gnc_numeric_zero();
+    for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
+    {
+        gnc_numeric value, tax;
+        GList *taxes;
+        GncEntry * entry = iter->data;
+        Account *this_acc;
+
+        /* Stabilize the TaxTable in this entry */
+        gncEntryBeginEdit (entry);
+        if (reverse)
+            gncEntrySetInvTaxTable
+            (entry, gncTaxTableReturnChild (gncEntryGetInvTaxTable (entry), TRUE));
+        else
+        {
+            gncEntrySetBillTaxTable
+            (entry, gncTaxTableReturnChild (gncEntryGetBillTaxTable (entry), TRUE));
+
+            /* If this is a bill, and the entry is billable, copy the price */
+            if (gncEntryGetBillable (entry))
+                gncEntrySetInvPrice (entry, gncEntryGetBillPrice (entry));
+        }
+        gncEntryCommitEdit (entry);
+
+        /* Obtain the Entry's Value and TaxValues */
+        gncEntryGetValue (entry, reverse, &value, NULL, &tax, &taxes);
+
+        /* add the value for the account split */
+        this_acc = (reverse ? gncEntryGetInvAccount (entry) :
+                    gncEntryGetBillAccount (entry));
+        if (this_acc)
+        {
+            if (gnc_numeric_check (value) == GNC_ERROR_OK)
+            {
+                if (accumulatesplits)
+                {
+                    splitinfo = gncAccountValueAdd (splitinfo, this_acc, value);
+                }
+                else
+                {
+                    Split *split;
+
+                    split = xaccMallocSplit (book);
+                    /* set action and memo? */
+
+                    xaccSplitSetMemo (split, gncEntryGetDescription (entry));
+                    xaccSplitSetAction (split, type);
+
+                    /* Need to insert this split into the account AND txn before
+                     * we set the Base Value.  Otherwise SetBaseValue complains
+                     * that we don't have an account and fails to set the value.
+                     */
+                    xaccAccountBeginEdit (this_acc);
+                    xaccAccountInsertSplit (this_acc, split);
+                    xaccAccountCommitEdit (this_acc);
+                    xaccTransAppendSplit (txn, split);
+
+                    if (gnc_commodity_equal(xaccAccountGetCommodity(this_acc), invoice->currency))
+                    {
+                        xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (value)
+                                                       : value),
+                                               invoice->currency);
+                    }
+                    else
+                    {
+                        /*need to do conversion */
+                        GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(this_acc));
+
+                        if (price == NULL)
+                        {
+                            /*This is an error, which shouldn't even be able to happen.
+                              We can't really do anything sensible about it, and this is
+                            		    a user-interface free zone so we can't try asking the user
+                              again either, have to return NULL*/
+                            return NULL;
+                        }
+                        else
+                        {
+                            gnc_numeric converted_amount;
+                            xaccSplitSetValue(split, (reverse ? gnc_numeric_neg(value) : value));
+                            converted_amount = gnc_numeric_div(value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
+                            printf("converting from %f to %f\n", gnc_numeric_to_double(value), gnc_numeric_to_double(converted_amount));
+                            xaccSplitSetAmount(split, reverse ? gnc_numeric_neg(converted_amount) : converted_amount);
+                        }
+                    }
+                }
+
+                /* If there is a credit-card account, and this is a CCard
+                 * payment type, the don't add it to the total, and instead
+                 * create a split to the CC Acct with a memo of the entry
+                 * description instead of the provided memo.  Note that the
+                 * value reversal is the same as the post account.
+                 *
+                 * Note: we don't have to worry about the tax values --
+                 * expense vouchers don't have them.
+                 */
+                if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD)
+                {
+                    Split *split;
+
+                    split = xaccMallocSplit (book);
+                    /* set action? */
+                    xaccSplitSetMemo (split, gncEntryGetDescription (entry));
+                    xaccSplitSetAction (split, type);
+                    xaccAccountBeginEdit (ccard_acct);
+                    xaccAccountInsertSplit (ccard_acct, split);
+                    xaccAccountCommitEdit (ccard_acct);
+                    xaccTransAppendSplit (txn, split);
+                    xaccSplitSetBaseValue (split, (reverse ? value : gnc_numeric_neg (value)),
+                                           invoice->currency);
+
+                }
+                else
+                    total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+
+            }
+            else
+                g_warning ("bad value in our entry");
+        }
+
+        /* now merge in the TaxValues */
+        splitinfo = gncAccountValueAddList (splitinfo, taxes);
+
+        /* ... and add the tax total */
+        if (gnc_numeric_check (tax) == GNC_ERROR_OK)
+            total = gnc_numeric_add (total, tax, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+        else
+            g_warning ("bad tax in our entry");
+
+    } /* for */
+
+    /* Iterate through the splitinfo list and generate the splits */
+    for (iter = splitinfo; iter; iter = iter->next)
+    {
+        Split *split;
+        GncAccountValue *acc_val = iter->data;
+
+        split = xaccMallocSplit (book);
+        /* set action and memo? */
+
+        xaccSplitSetMemo (split, memo);
+        xaccSplitSetAction (split, type);
+
+        xaccAccountBeginEdit (acc_val->account);
+        xaccAccountInsertSplit (acc_val->account, split);
+        xaccAccountCommitEdit (acc_val->account);
+        xaccTransAppendSplit (txn, split);
+
+        if (gnc_commodity_equal(xaccAccountGetCommodity(acc_val->account), invoice->currency))
+        {
+            xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (acc_val->value)
+                                           : acc_val->value),
+                                   invoice->currency);
+        }
+        else
+        {
+            /*need to do conversion */
+            GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(acc_val->account));
+
+            if (price == NULL)
+            {
+                /*This is an error, which shouldn't even be able to happen.
+                  We can't really do anything sensible about it, and this is
+                  a user-interface free zone so we can't try asking the user
+                  again either, have to return NULL*/
+                return NULL;
+            }
+            else
+            {
+                gnc_numeric converted_amount;
+                xaccSplitSetValue(split, (reverse ? gnc_numeric_neg(acc_val->value) : acc_val->value));
+                converted_amount = gnc_numeric_div(acc_val->value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
+                printf("converting from %f to %f\n", gnc_numeric_to_double(acc_val->value), gnc_numeric_to_double(converted_amount));
+
+                xaccSplitSetAmount(split, reverse ? gnc_numeric_neg(converted_amount) : converted_amount);
+            }
+        }
+    }
+
+    /* If there is a ccard account, we may have an additional "to_card" payment.
+     * we should make that now..
+     */
+    if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount))
+    {
+        Split *split = xaccMallocSplit (book);
+
+        /* Set memo.  action? */
+        xaccSplitSetMemo (split, _("Extra to Charge Card"));
+        xaccSplitSetAction (split, type);
+
+        xaccAccountBeginEdit (ccard_acct);
+        xaccAccountInsertSplit (ccard_acct, split);
+        xaccAccountCommitEdit (ccard_acct);
+        xaccTransAppendSplit (txn, split);
+        xaccSplitSetBaseValue (split, (reverse ? invoice->to_charge_amount :
+                                       gnc_numeric_neg(invoice->to_charge_amount)),
+                               invoice->currency);
+
+        total = gnc_numeric_sub (total, invoice->to_charge_amount,
+                                 GNC_DENOM_AUTO, GNC_DENOM_LCD);
+    }
+
+    /* Now create the Posted split (which is negative -- it's a credit) */
+    {
+        Split *split = xaccMallocSplit (book);
+
+        /* Set action/memo */
+        xaccSplitSetMemo (split, memo);
+        xaccSplitSetAction (split, type);
+
+        xaccAccountBeginEdit (acc);
+        xaccAccountInsertSplit (acc, split);
+        xaccAccountCommitEdit (acc);
+        xaccTransAppendSplit (txn, split);
+        xaccSplitSetBaseValue (split, (reverse ? total : gnc_numeric_neg (total)),
+                               invoice->currency);
+
+        /* add this split to the lot */
+        gnc_lot_add_split (lot, split);
+    }
+
+    /* Now attach this invoice to the txn, lot, and account */
+    gncInvoiceAttachToLot (invoice, lot);
+    gncInvoiceAttachToTxn (invoice, txn);
+    gncInvoiceSetPostedAcc (invoice, acc);
+
+    xaccTransSetReadOnly (txn, _("Generated from an invoice.  Try unposting the invoice."));
+    xaccTransCommitEdit (txn);
+
+    gncAccountValueDestroy (splitinfo);
+
+    /* check the lot -- if we still look like a payment lot, then that
+     * means we need to create a balancing split and create a new payment
+     * lot for the next invoice
+     *
+     * we're looking for a positive balance for bill/AP, and a negative balance
+     * for invoice/AR.
+     * (because bill payments debit AP accounts and invoice payments
+     * credit AR accounts)
+     */
+    total = gnc_lot_get_balance (lot);
+
+    if ( (gnc_numeric_negative_p (total) && reverse) ||
+            (gnc_numeric_positive_p (total) && !reverse) )
+    {
+        Transaction *t2;
+        GNCLot *lot2;
+        Split *split;
+        /* Translators: This is the memo of an auto-created split */
+        char *memo2 = _("Automatic Payment Forward");
+        char *action2 = _("Auto Split");
+
+        t2 = xaccMallocTransaction (book);
+        lot2 = gnc_lot_new (book);
+        gnc_lot_begin_edit (lot2);
+        gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)),
+                             lot2);
+
+        xaccTransBeginEdit (t2);
+        xaccAccountBeginEdit (acc);
+
+        /* Set Transaction Description (Owner Name), Currency */
+        xaccTransSetDescription (t2, name ? name : "");
+        xaccTransSetCurrency (t2, invoice->currency);
+
+        /* Entered and Posted at date */
+        xaccTransSetDateEnteredSecs (t2, time(NULL));
+        if (post_date)
+            xaccTransSetDatePostedTS (t2, post_date);
+
+        /* Balance out this lot */
+        split = xaccMallocSplit (book);
+        xaccSplitSetMemo (split, memo2);
+        xaccSplitSetAction (split, action2);
+        xaccAccountInsertSplit (acc, split);
+        xaccTransAppendSplit (t2, split);
+        // the value of total used here is correct for both bill/AP and
+        // invoice/AR. See the comment before this if block
+        xaccSplitSetBaseValue (split, gnc_numeric_neg (total),
+                               invoice->currency);
+        gnc_lot_add_split (lot, split);
+
+        /* And apply the pre-payment to a new lot */
+        split = xaccMallocSplit (book);
+        xaccSplitSetMemo (split, memo2);
+        xaccSplitSetAction (split, action2);
+        xaccAccountInsertSplit (acc, split);
+        xaccTransAppendSplit (t2, split);
+        xaccSplitSetBaseValue (split, total, invoice->currency);
+        gnc_lot_add_split (lot2, split);
+
+        gnc_lot_commit_edit (lot2);
+        xaccTransCommitEdit (t2);
+        xaccAccountCommitEdit (acc);
+    }
+
+    gnc_lot_commit_edit (lot);
+    gncInvoiceCommitEdit (invoice);
+
+    return txn;
+}
+
+gboolean
+gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
+{
+    Transaction *txn;
+    GNCLot *lot;
+
+    if (!invoice) return FALSE;
+    if (!gncInvoiceIsPosted (invoice)) return FALSE;
+
+    txn = gncInvoiceGetPostedTxn (invoice);
+    g_return_val_if_fail (txn, FALSE);
+
+    lot = gncInvoiceGetPostedLot (invoice);
+    g_return_val_if_fail (lot, FALSE);
+
+    /* Destroy the Posted Transaction */
+    xaccTransClearReadOnly (txn);
+    xaccTransBeginEdit (txn);
+    xaccTransDestroy (txn);
+    xaccTransCommitEdit (txn);
+
+    /* Disconnect the lot from the invoice; re-attach to the invoice owner */
+    gncInvoiceDetachFromLot (lot);
+    gncOwnerAttachToLot (&invoice->owner, lot);
+
+    /* If the lot has no splits, then destroy it */
+    if (!gnc_lot_count_splits (lot))
+        gnc_lot_destroy (lot);
+
+    /* Clear out the invoice posted information */
+    gncInvoiceBeginEdit (invoice);
+
+    invoice->posted_acc = NULL;
+    invoice->posted_txn = NULL;
+    invoice->posted_lot = NULL;
+    invoice->date_posted.tv_sec = invoice->date_posted.tv_nsec = 0;
+
+    /* if we've been asked to reset the tax tables, then do so */
+    if (reset_tax_tables)
+    {
+        gboolean reverse = (gncInvoiceGetOwnerType(invoice) == GNC_OWNER_CUSTOMER);
+        GList *iter;
+
+        for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
+        {
+            GncEntry *entry = iter->data;
+
+            gncEntryBeginEdit(entry);
+            if (reverse)
+                gncEntrySetInvTaxTable(entry,
+                                       gncTaxTableGetParent(gncEntryGetInvTaxTable(entry)));
+            else
+                gncEntrySetBillTaxTable(entry,
+                                        gncTaxTableGetParent(gncEntryGetBillTaxTable(entry)));
+            gncEntryCommitEdit(entry);
+        }
+    }
+
+    mark_invoice (invoice);
+    gncInvoiceCommitEdit (invoice);
+
+    return TRUE;
+}
+
+static gboolean
+gnc_lot_match_invoice_owner (GNCLot *lot, gpointer user_data)
+{
+    GncOwner owner_def, *owner, *this_owner = user_data;
+    GncInvoice *invoice;
+
+    /* If this lot is not for this owner, then ignore it */
+    invoice = gncInvoiceGetInvoiceFromLot (lot);
+    if (invoice)
+    {
+        owner = gncInvoiceGetOwner (invoice);
+        owner = gncOwnerGetEndOwner (owner);
+    }
+    else
+    {
+        if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
+            return FALSE;
+        owner = gncOwnerGetEndOwner (&owner_def);
+    }
+
+    return gncOwnerEqual (owner, this_owner);
+}
+
+static gint
+gnc_lot_sort_func (GNCLot *a, GNCLot *b)
+{
+    GncInvoice *ia, *ib;
+    Timespec da, db;
+
+    ia = gncInvoiceGetInvoiceFromLot (a);
+    ib = gncInvoiceGetInvoiceFromLot (b);
+
+    da = gncInvoiceGetDateDue (ia);
+    db = gncInvoiceGetDateDue (ib);
+
+    return timespec_cmp (&da, &db);
+}
+
+/*
+ * Apply a payment of "amount" for the owner, between the xfer_account
+ * (bank or other asset) and the posted_account (A/R or A/P).
+ *
+ * XXX: yes, this should be in gncOwner, but all the other logic is
+ * in gncInvoice...
+ */
+Transaction *
+gncOwnerApplyPayment (GncOwner *owner, GncInvoice* invoice,
+                      Account *posted_acc, Account *xfer_acc,
+                      gnc_numeric amount, gnc_numeric exch, Timespec date,
+                      const char *memo, const char *num)
+{
+    QofBook *book;
+    Account *inv_posted_acc;
+    Transaction *txn;
+    Split *split;
+    GList *lot_list, *fifo = NULL;
+    GNCLot *lot, *inv_posted_lot = NULL, *prepay_lot = NULL;
+    GncInvoice *this_invoice;
+    const char *name;
+    gnc_commodity *commodity;
+    gnc_numeric split_amt;
+    gboolean reverse, inv_passed = TRUE;
+    gnc_numeric payment_value = amount;
+
+    /* Verify our arguments */
+    if (!owner || !posted_acc || !xfer_acc) return NULL;
+    g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
+
+    /* Compute the ancillary data */
+    book = gnc_account_get_book (posted_acc);
+    name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
+    commodity = gncOwnerGetCurrency (owner);
+    reverse = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER);
+
+    txn = xaccMallocTransaction (book);
+    xaccTransBeginEdit (txn);
+
+    /* Set up the transaction */
+    xaccTransSetDescription (txn, name ? name : "");
+    xaccTransSetNum (txn, num);
+    xaccTransSetCurrency (txn, commodity);
+    xaccTransSetDateEnteredSecs (txn, time(NULL));
+    xaccTransSetDatePostedTS (txn, &date);
+    xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT);
+
+
+    /* The split for the transfer account */
+    split = xaccMallocSplit (book);
+    xaccSplitSetMemo (split, memo);
+    xaccSplitSetAction (split, _("Payment"));
+    xaccAccountBeginEdit (xfer_acc);
+    xaccAccountInsertSplit (xfer_acc, split);
+    xaccAccountCommitEdit (xfer_acc);
+    xaccTransAppendSplit (txn, split);
+
+    if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity))
+    {
+        xaccSplitSetBaseValue (split, reverse ? amount :
+                               gnc_numeric_neg (amount), commodity);
+    }
+    else
+    {
+        /* Need to value the payment in terms of the owner commodity */
+        xaccSplitSetAmount(split, reverse ? amount : gnc_numeric_neg (amount));
+        payment_value = gnc_numeric_mul(amount, exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
+        xaccSplitSetValue(split, reverse ? payment_value : gnc_numeric_neg(payment_value));
+    }
+
+
+    /* Now, find all "open" lots in the posting account for this
+     * company and apply the payment on a FIFO basis.  Create
+     * a new split for each open lot until the payment is gone.
+     */
+
+    fifo = xaccAccountFindOpenLots (posted_acc, gnc_lot_match_invoice_owner,
+                                    owner,
+                                    (GCompareFunc)gnc_lot_sort_func);
+
+    /* Check if an invoice was passed in, and if so, does it match the
+     * account, and is it an open lot?  If so, put it at the beginning
+     * of the lot list fifo so we post to this invoice's lot first.
+     */
+    if (invoice)
+    {
+        inv_posted_acc = gncInvoiceGetPostedAcc(invoice);
+        inv_posted_lot = gncInvoiceGetPostedLot(invoice);
+        if (inv_posted_acc && inv_posted_lot &&
+                guid_equal(xaccAccountGetGUID(inv_posted_acc),
+                           xaccAccountGetGUID(posted_acc)) &&
+                !gnc_lot_is_closed(inv_posted_lot))
+        {
+            /* Put this invoice at the beginning of the FIFO */
+            fifo = g_list_prepend (fifo, inv_posted_lot);
+            inv_passed = FALSE;
+        }
+    }
+
+    xaccAccountBeginEdit (posted_acc);
+
+    /* Now iterate over the fifo until the payment is fully applied
+     * (or all the lots are paid)
+     */
+    for (lot_list = fifo; lot_list; lot_list = lot_list->next)
+    {
+        gnc_numeric balance;
+
+        lot = lot_list->data;
+
+        /* Skip this lot if it matches the invoice that was passed in and
+         * we've seen it already.  This way we post to it the first time
+         * (from the beginning of the lot-list) but not when we reach it
+         * the second time.
+         */
+        if (inv_posted_lot &&
+                guid_equal(qof_instance_get_guid(QOF_INSTANCE(lot)),
+                           qof_instance_get_guid(QOF_INSTANCE(inv_posted_lot))))
+        {
+            if (inv_passed)
+                continue;
+            else
+                inv_passed = TRUE;
+        }
+
+        balance = gnc_lot_get_balance (lot);
+
+        if (!reverse)
+            balance = gnc_numeric_neg (balance);
+
+        /* If the balance is "negative" then skip this lot.
+         * (just save the pre-payment lot for later)
+         */
+        if (gnc_numeric_negative_p (balance))
+        {
+            if (prepay_lot)
+            {
+                g_warning ("Multiple pre-payment lots are found.  Skipping.");
+            }
+            else
+            {
+                prepay_lot = lot;
+            }
+            continue;
+        }
+
+        /*
+         * If the payment_value <= the balance; we're done -- apply the payment_value.
+         * Otherwise, apply the balance, subtract that from the payment_value,
+         * and move on to the next one.
+         */
+        if (gnc_numeric_compare (payment_value, balance) <= 0)
+        {
+            /* payment_value <= balance */
+            split_amt = payment_value;
+        }
+        else
+        {
+            /* payment_value > balance */
+            split_amt = balance;
+        }
+
+        /* reduce the payment_value by split_amt */
+        payment_value = gnc_numeric_sub (payment_value, split_amt, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+
+        /* Create the split for this lot in the post account */
+        split = xaccMallocSplit (book);
+        xaccSplitSetMemo (split, memo);
+        xaccSplitSetAction (split, _("Payment"));
+        xaccAccountInsertSplit (posted_acc, split);
+        xaccTransAppendSplit (txn, split);
+        xaccSplitSetBaseValue (split, reverse ? gnc_numeric_neg (split_amt) :
+                               split_amt, commodity);
+        gnc_lot_add_split (lot, split);
+
+        /* Now send an event for the invoice so it gets updated as paid */
+        this_invoice = gncInvoiceGetInvoiceFromLot(lot);
+        if (this_invoice)
+            qof_event_gen (&this_invoice->inst, QOF_EVENT_MODIFY, NULL);
+
+        if (gnc_numeric_zero_p (payment_value))
+            break;
+    }
+
+    g_list_free (fifo);
+
+    /* If there is still money left here, then create a pre-payment lot */
+    if (gnc_numeric_positive_p (payment_value))
+    {
+        if (prepay_lot == NULL)
+        {
+            prepay_lot = gnc_lot_new (book);
+            gncOwnerAttachToLot (owner, prepay_lot);
+        }
+
+        split = xaccMallocSplit (book);
+        xaccSplitSetMemo (split, memo);
+        xaccSplitSetAction (split, _("Pre-Payment"));
+        xaccAccountInsertSplit (posted_acc, split);
+        xaccTransAppendSplit (txn, split);
+        xaccSplitSetBaseValue (split, reverse ? gnc_numeric_neg (payment_value) :
+                               payment_value, commodity);
+        gnc_lot_add_split (prepay_lot, split);
+    }
+
+    xaccAccountCommitEdit (posted_acc);
+
+    /* Commit this new transaction */
+    xaccTransCommitEdit (txn);
+
+    return txn;
+}
+
+static gboolean gncInvoiceDateExists (const Timespec *date)
+{
+    g_return_val_if_fail (date, FALSE);
+    if (date->tv_sec || date->tv_nsec) return TRUE;
+    return FALSE;
+}
+
+gboolean gncInvoiceIsPosted (const GncInvoice *invoice)
+{
+    if (!invoice) return FALSE;
+    return gncInvoiceDateExists (&(invoice->date_posted));
+}
+
+gboolean gncInvoiceIsPaid (const GncInvoice *invoice)
+{
+    if (!invoice) return FALSE;
+    if (!invoice->posted_lot) return FALSE;
+    return gnc_lot_is_closed(invoice->posted_lot);
+}
+
+/* ================================================================== */
+
+void gncInvoiceBeginEdit (GncInvoice *invoice)
+{
+    qof_begin_edit(&invoice->inst);
+}
+
+static void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("Invoice QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncInvoiceOnDone (QofInstance *invoice) { }
+
+static void invoice_free (QofInstance *inst)
+{
+    GncInvoice *invoice = (GncInvoice *) inst;
+    gncInvoiceFree (invoice);
+}
+
+void gncInvoiceCommitEdit (GncInvoice *invoice)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(invoice))) return;
+    qof_commit_edit_part2 (&invoice->inst, gncInvoiceOnError,
+                           gncInvoiceOnDone, invoice_free);
+}
+
+int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
+{
+    int compare;
+
+    if (a == b) return 0;
+    if (!a && b) return -1;
+    if (a && !b) return 1;
+
+    compare = safe_strcmp (a->id, b->id);
+    if (compare) return compare;
+
+    compare = timespec_cmp (&(a->date_opened), &(b->date_opened));
+    if (compare) return compare;
+
+    compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
+    if (compare) return compare;
+
+    return qof_instance_guid_compare(a, b);
+}
+
+gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_INVOICE(a), FALSE);
+    g_return_val_if_fail(GNC_IS_INVOICE(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->notes, b->notes) != 0)
+    {
+        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->billing_id, b->billing_id) != 0)
+    {
+        PWARN("Billing IDs differ: %s vs %s", a->billing_id, b->billing_id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->printname, b->printname) != 0)
+    {
+        PWARN("Printnames differ: %s vs %s", a->printname, b->printname);
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+    if (!gncBillTermEqual(a->terms, b->terms))
+    {
+        PWARN("Billterms differ");
+        return FALSE;
+    }
+
+    if (!gncJobEqual(a->job, b->job))
+    {
+        PWARN("Jobs differ");
+        return FALSE;
+    }
+
+    if (!gnc_commodity_equal(a->currency, b->currency))
+    {
+        PWARN("Currencies differ");
+        return FALSE;
+    }
+
+    if (!xaccAccountEqual(a->posted_acc, b->posted_acc, TRUE))
+    {
+        PWARN("Posted accounts differ");
+        return FALSE;
+    }
+
+    if (!xaccTransEqual(a->posted_txn, b->posted_txn, TRUE, TRUE, TRUE, FALSE))
+    {
+        PWARN("Posted tx differ");
+        return FALSE;
+    }
+
+#if 0
+    if (!gncLotEqual(a->posted_lot, b->posted_lot))
+    {
+        PWARN("Posted lots differ");
+        return FALSE;
+    }
+#endif
+
+    /* FIXME: Need real checks */
+#if 0
+    GList       *entries;
+    GList       *prices;
+    GncOwner    owner;
+    GncOwner    billto;
+    Timespec    date_opened;
+    Timespec    date_posted;
+
+    gnc_numeric	to_charge_amount;
+#endif
+
+    return TRUE;
+}
+
+/* ============================================================= */
+/* Package-Private functions */
+
+static const char * _gncInvoicePrintable (gpointer obj)
+{
+    GncInvoice *invoice = obj;
+
+    g_return_val_if_fail (invoice, NULL);
+
+    if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL)
+    {
+        if (invoice->printname) g_free (invoice->printname);
+
+        invoice->printname =
+            g_strdup_printf ("%s%s", invoice->id,
+                             gncInvoiceIsPosted (invoice) ? _(" (posted)") : "");
+    }
+
+    return invoice->printname;
+}
+
+static QofObject gncInvoiceDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Invoice",
+    DI(.create            = ) (gpointer)gncInvoiceCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) _gncInvoicePrintable,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+static void
+reg_lot (void)
+{
+    static QofParam params[] =
+    {
+        {
+            INVOICE_FROM_LOT, _GNC_MOD_NAME,
+            (QofAccessFunc)gncInvoiceGetInvoiceFromLot, NULL
+        },
+        { NULL },
+    };
+
+    qof_class_register (GNC_ID_LOT, NULL, params);
+}
+
+static void
+reg_txn (void)
+{
+    static QofParam params[] =
+    {
+        {
+            INVOICE_FROM_TXN, _GNC_MOD_NAME,
+            (QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL
+        },
+        { NULL },
+    };
+
+    qof_class_register (GNC_ID_TRANS, NULL, params);
+}
+
+gboolean gncInvoiceRegister (void)
+{
+    static QofParam params[] =
+    {
+        { INVOICE_ID,      QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID,     (QofSetterFunc)gncInvoiceSetID },
+        { INVOICE_OWNER,   GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
+        { INVOICE_OPENED,  QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
+        { INVOICE_DUE,     QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDateDue, NULL },
+        { INVOICE_POSTED,  QOF_TYPE_DATE,   (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
+        { INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL },
+        { INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid,    NULL },
+        { INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, (QofSetterFunc)gncInvoiceSetBillingID },
+        { INVOICE_NOTES,   QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes,   (QofSetterFunc)gncInvoiceSetNotes },
+        { INVOICE_ACC,     GNC_ID_ACCOUNT,  (QofAccessFunc)gncInvoiceGetPostedAcc, (QofSetterFunc)gncInvoiceSetPostedAcc },
+        { INVOICE_POST_TXN, GNC_ID_TRANS,   (QofAccessFunc)gncInvoiceGetPostedTxn, (QofSetterFunc)gncInvoiceSetPostedTxn },
+        { INVOICE_POST_LOT, GNC_ID_LOT,     (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
+        { INVOICE_TYPE,    QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType,    NULL },
+        { INVOICE_TERMS,   GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms,   (QofSetterFunc)gncInvoiceSetTerms },
+        { INVOICE_BILLTO,  GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL  },
+        { INVOICE_ENTRIES, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
+        { INVOICE_JOB,     GNC_ID_JOB,      (QofAccessFunc)qofInvoiceGetJob,     (QofSetterFunc)qofInvoiceSetJob },
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, (QofSetterFunc)gncInvoiceSetActive },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params);
+    reg_lot ();
+    reg_txn ();
+
+    /* Make the compiler happy... */
+    if (0)
+    {
+        qofInvoiceSetEntries(NULL, NULL);
+        qofInvoiceGetEntries(NULL);
+        qofInvoiceSetOwner(NULL, NULL);
+        qofInvoiceGetOwner(NULL);
+        qofInvoiceSetBillTo(NULL, NULL);
+        qofInvoiceGetBillTo(NULL);
+    }
+    if (!qof_choice_create(GNC_ID_INVOICE))
+    {
+        return FALSE;
+    }
+    return qof_object_register (&gncInvoiceDesc);
+}
+
+gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner)
+{
+    gint64 nextID;
+    switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
+    {
+    case GNC_OWNER_CUSTOMER:
+        nextID = qof_book_get_counter (book, "gncInvoice");
+        break;
+    case GNC_OWNER_VENDOR:
+        nextID = qof_book_get_counter (book, "gncBill");
+        break;
+    case GNC_OWNER_EMPLOYEE:
+        nextID = qof_book_get_counter (book, "gncExpVoucher");
+        break;
+    default:
+        nextID = qof_book_get_counter (book, _GNC_MOD_NAME);
+        break;
+    }
+    return nextID;
+}

Copied: gnucash/trunk/src/engine/gncInvoice.h (from rev 19328, gnucash/trunk/src/business/business-core/gncInvoice.h)
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncInvoice.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,231 @@
+/********************************************************************\
+ * gncInvoice.h -- the Core Business Invoice Interface              *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Invoice
+
+An invoice holds a list of entries, a pointer to the customer,
+and the job, the dates entered and posted, as well as the account,
+transaction and lot for the posted invoice.
+    @{ */
+/** @file gncInvoice.h
+    @brief  Business Invoice Interface
+    @author Copyright (C) 2001,2006 Derek Atkins <warlord at MIT.EDU>
+    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+*/
+
+#ifndef GNC_INVOICE_H_
+#define GNC_INVOICE_H_
+
+struct _gncInvoice;
+typedef struct _gncInvoice GncInvoice;
+typedef struct _gncInvoiceClass GncInvoiceClass;
+
+#include "gncBillTerm.h"
+#include "gncEntry.h"
+#include "gncOwner.h"
+#include "gnc-lot.h"
+#include "qofbook.h"
+#include "qofbook.h"
+#include "gnc-pricedb.h"
+
+#define GNC_ID_INVOICE    "gncInvoice"
+
+/* --- type macros --- */
+#define GNC_TYPE_INVOICE            (gnc_invoice_get_type ())
+#define GNC_INVOICE(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_INVOICE, GncInvoice))
+#define GNC_INVOICE_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_INVOICE, GncInvoiceClass))
+#define GNC_IS_INVOICE(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_INVOICE))
+#define GNC_IS_INVOICE_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_INVOICE))
+#define GNC_INVOICE_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
+GType gnc_invoice_get_type(void);
+
+/** @name Create/Destroy Functions
+ @{ */
+GncInvoice *gncInvoiceCreate (QofBook *book);
+void gncInvoiceDestroy (GncInvoice *invoice);
+/** @} */
+
+/** @name Set Functions
+ @{ */
+void gncInvoiceSetID (GncInvoice *invoice, const char *id);
+void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
+void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date);
+void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date);
+void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms);
+void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id);
+void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
+void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency);
+void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
+void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
+void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
+/** @} */
+
+void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry);
+void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry);
+void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price);
+void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price);
+
+/** Call this function when adding an entry to a bill instead of an invoice */
+void gncBillAddEntry (GncInvoice *bill, GncEntry *entry);
+void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
+void gncBillAddPrice (GncInvoice *bill, GNCPrice *price);
+void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price);
+
+/** Call this function when an Entry is changed and you want to
+    re-sort the list of entries
+*/
+void gncInvoiceSortEntries (GncInvoice *invoice);
+
+/** @name Get Functions
+ @{ */
+const char * gncInvoiceGetID (const GncInvoice *invoice);
+GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
+Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice);
+Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice);
+Timespec gncInvoiceGetDateDue (const GncInvoice *invoice);
+GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
+const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
+const char * gncInvoiceGetNotes (const GncInvoice *invoice);
+GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
+const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type);
+const char * gncInvoiceGetType (GncInvoice *invoice);
+gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
+GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
+gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
+gboolean gncInvoiceGetActive (const GncInvoice *invoice);
+
+GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
+Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
+Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
+/** @} */
+
+/** return the "total" amount of the invoice */
+gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice);
+gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type);
+gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice);
+gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice);
+
+typedef GList EntryList;
+EntryList * gncInvoiceGetEntries (GncInvoice *invoice);
+GList * gncInvoiceGetPrices(GncInvoice *invoice);
+GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity* commodity);
+
+/** Post this invoice to an account.  Returns the new Transaction
+ * that is tied to this invoice.   The transaction is set with
+ * the supplied posted date, due date, and memo.  The Transaction
+ * description is set to the name of the company.
+ */
+Transaction *
+gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
+                         Timespec *posted_date, Timespec *due_date,
+                         const char *memo, gboolean accumulatesplits);
+
+/**
+ * UNpost this invoice.  This will destroy the posted transaction and
+ * return the invoice to its unposted state.  It may leave empty lots
+ * out there.  If reset_tax_tables is TRUE, then it will also revert
+ * all the Tax Tables to the parent, which will potentially change the
+ * total value of the invoice.  It may also leave some orphaned Tax
+ * Table children.
+ *
+ * Returns TRUE if successful, FALSE if there is a problem.
+ */
+gboolean
+gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
+
+/**
+ * Apply a payment of "amount" for the owner, between the xfer_account
+ * (bank or other asset) and the posted_account (A/R or A/P).  If the
+ * caller supplies an (optional) invoice argument, then apply the
+ * payment to that invoice first before any other invoice.
+ *
+ * XXX: yes, this should be in gncOwner, but all the other logic is
+ * in gncInvoice...
+ */
+Transaction *
+gncOwnerApplyPayment (GncOwner *owner, GncInvoice *invoice,
+                      Account *posted_acc, Account *xfer_acc,
+                      gnc_numeric amount, gnc_numeric exch, Timespec date,
+                      const char *memo, const char *num);
+
+
+/** Given a transaction, find and return the Invoice */
+GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
+
+/** Given a LOT, find and return the Invoice attached to the lot */
+GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
+
+/** Return a pointer to the instance gncInvoice that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncInvoice * gncInvoiceLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
+}
+
+void gncInvoiceBeginEdit (GncInvoice *invoice);
+void gncInvoiceCommitEdit (GncInvoice *invoice);
+int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
+gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b);
+gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
+gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
+
+#define INVOICE_ID	"id"
+#define INVOICE_OWNER	"owner"
+#define INVOICE_OPENED	"date_opened"
+#define INVOICE_POSTED	"date_posted"
+#define INVOICE_DUE	"date_due"
+#define INVOICE_IS_POSTED	"is_posted?"
+#define INVOICE_IS_PAID	"is_paid?"
+#define INVOICE_TERMS	"terms"
+#define INVOICE_BILLINGID	"billing_id"
+#define INVOICE_NOTES	"notes"
+#define INVOICE_ACC	"account"
+#define INVOICE_POST_TXN	"posted_txn"
+#define INVOICE_POST_LOT	"posted_lot"
+#define INVOICE_TYPE	"type"
+#define INVOICE_BILLTO	"bill-to"
+#define INVOICE_ENTRIES     "list_of_entries"
+#define INVOICE_JOB         "invoice_job"
+
+#define INVOICE_FROM_LOT	"invoice-from-lot"
+#define INVOICE_FROM_TXN	"invoice-from-txn"
+
+QofBook *gncInvoiceGetBook(GncInvoice *x);
+
+/** deprecated functions */
+#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+#define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
+#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G))
+
+#endif /* GNC_INVOICE_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncInvoiceP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncInvoiceP.h)
===================================================================
--- gnucash/trunk/src/engine/gncInvoiceP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncInvoiceP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,68 @@
+/********************************************************************\
+ * gncInvoiceP.h -- the Core Busines Invoice Interface              *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_INVOICEP_H_
+#define GNC_INVOICEP_H_
+
+#include "gncInvoice.h"
+#include "Account.h"
+#include "Transaction.h"
+#include "gnc-lot.h"
+#include "gncOwner.h"
+
+gboolean gncInvoiceRegister (void);
+gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner);
+void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
+void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
+void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
+void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
+
+
+/** The gncCloneInvoice() routine makes a copy of the indicated
+ *  invoice, placing it in the indicated book.  It copies
+ *  the name, description, type, due-days, discount, etc.
+ *  It also copies (as needed) both parents and children, so that
+ *  the parent-child relationship is correctly mirrored in the
+ *  clone.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *);
+
+/** The gncInvoiceObtainTwin() will find the 'twin' of the
+ *  indicated invoice in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneInvoice()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book);
+#define gncInvoiceSetGUID(I,G) qof_instance_set_guid(QOF_INSTANCE(I),(G))
+#endif /* GNC_INVOICEP_H_ */

Copied: gnucash/trunk/src/engine/gncJob.c (from rev 19328, gnucash/trunk/src/business/business-core/gncJob.c)
===================================================================
--- gnucash/trunk/src/engine/gncJob.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncJob.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,568 @@
+/********************************************************************\
+ * gncJob.c -- the Core Job Interface                               *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001, 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>
+
+#include "gncInvoice.h"
+#include "gncJob.h"
+#include "gncJobP.h"
+#include "gncOwnerP.h"
+
+struct _gncJob
+{
+    QofInstance inst;
+    char *        id;
+    char *        name;
+    char *        desc;
+    GncOwner      owner;
+    gboolean      active;
+};
+
+struct _gncJobClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME        GNC_ID_JOB
+
+/* ================================================================== */
+/* misc inline functions */
+
+G_INLINE_FUNC void mark_job (GncJob *job);
+void mark_job (GncJob *job)
+{
+    qof_instance_set_dirty(&job->inst);
+    qof_event_gen (&job->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* ================================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncJob, gnc_job, QOF_TYPE_INSTANCE);
+
+static void
+gnc_job_init(GncJob* job)
+{
+}
+
+static void
+gnc_job_dispose(GObject *jobp)
+{
+    G_OBJECT_CLASS(gnc_job_parent_class)->dispose(jobp);
+}
+
+static void
+gnc_job_finalize(GObject* jobp)
+{
+    G_OBJECT_CLASS(gnc_job_parent_class)->finalize(jobp);
+}
+
+static void
+gnc_job_get_property (GObject         *object,
+                      guint            prop_id,
+                      GValue          *value,
+                      GParamSpec      *pspec)
+{
+    GncJob *job;
+
+    g_return_if_fail(GNC_IS_JOB(object));
+
+    job = GNC_JOB(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, job->name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_job_set_property (GObject         *object,
+                      guint            prop_id,
+                      const GValue          *value,
+                      GParamSpec      *pspec)
+{
+    GncJob *job;
+
+    g_return_if_fail(GNC_IS_JOB(object));
+
+    job = GNC_JOB(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncJobSetName(job, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing */
+    return NULL;
+}
+
+static void
+gnc_job_class_init (GncJobClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_job_dispose;
+    gobject_class->finalize = gnc_job_finalize;
+    gobject_class->set_property = gnc_job_set_property;
+    gobject_class->get_property = gnc_job_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "Job Name",
+                          "The job name is an arbitrary string "
+                          "assigned by the user.  It is intended to "
+                          "a short character string that is displayed "
+                          "by the GUI as the job mnemonic.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncJob *gncJobCreate (QofBook *book)
+{
+    GncJob *job;
+
+    if (!book) return NULL;
+
+    job = g_object_new (GNC_TYPE_JOB, NULL);
+    qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
+
+    job->id = CACHE_INSERT ("");
+    job->name = CACHE_INSERT ("");
+    job->desc = CACHE_INSERT ("");
+    job->active = TRUE;
+
+    /* GncOwner not initialized */
+    qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
+
+    return job;
+}
+
+GncJob *
+gncCloneJob (GncJob *from, QofBook *book)
+{
+    GncJob *job;
+
+    if (!book) return NULL;
+
+    job = g_object_new (GNC_TYPE_JOB, NULL);
+    qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&job->inst, &from->inst);
+
+    job->id = CACHE_INSERT (from->id);
+    job->name = CACHE_INSERT (from->name);
+    job->desc = CACHE_INSERT (from->desc);
+    job->active = from->active;
+
+    job->owner = gncCloneOwner(&from->owner, book);
+
+    qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
+
+    return job;
+}
+
+void gncJobDestroy (GncJob *job)
+{
+    if (!job) return;
+    qof_instance_set_destroying(job, TRUE);
+    gncJobCommitEdit (job);
+}
+
+static void gncJobFree (GncJob *job)
+{
+    if (!job) return;
+
+    qof_event_gen (&job->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (job->id);
+    CACHE_REMOVE (job->name);
+    CACHE_REMOVE (job->desc);
+
+    switch (gncOwnerGetType (&(job->owner)))
+    {
+    case GNC_OWNER_CUSTOMER:
+        gncCustomerRemoveJob (gncOwnerGetCustomer(&job->owner), job);
+        break;
+    case GNC_OWNER_VENDOR:
+        gncVendorRemoveJob (gncOwnerGetVendor(&job->owner), job);
+        break;
+    default:
+        break;
+    }
+
+    /* qof_instance_release (&job->inst); */
+    g_object_unref (job);
+}
+
+GncJob *
+gncJobObtainTwin (GncJob *from, QofBook *book)
+{
+    GncJob *job;
+    if (!from) return NULL;
+
+    job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!job)
+    {
+        job = gncCloneJob (from, book);
+    }
+    return job;
+}
+
+/* ================================================================== */
+/* Set Functions */
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncJobBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+void gncJobSetID (GncJob *job, const char *id)
+{
+    if (!job) return;
+    if (!id) return;
+    SET_STR(job, job->id, id);
+    mark_job (job);
+    gncJobCommitEdit (job);
+}
+
+void gncJobSetName (GncJob *job, const char *name)
+{
+    if (!job) return;
+    if (!name) return;
+    SET_STR(job, job->name, name);
+    mark_job (job);
+    gncJobCommitEdit (job);
+}
+
+void gncJobSetReference (GncJob *job, const char *desc)
+{
+    if (!job) return;
+    if (!desc) return;
+    SET_STR(job, job->desc, desc);
+    mark_job (job);
+    gncJobCommitEdit (job);
+}
+
+void gncJobSetOwner (GncJob *job, GncOwner *owner)
+{
+    if (!job) return;
+    if (!owner) return;
+    if (gncOwnerEqual (owner, &(job->owner))) return;
+
+    switch (gncOwnerGetType (owner))
+    {
+    case GNC_OWNER_CUSTOMER:
+    case GNC_OWNER_VENDOR:
+        break;
+    default:
+        PERR("Unsupported Owner type: %d", gncOwnerGetType(owner));
+        return;
+    }
+
+    gncJobBeginEdit (job);
+
+    switch (gncOwnerGetType (&(job->owner)))
+    {
+    case GNC_OWNER_CUSTOMER:
+        gncCustomerRemoveJob (gncOwnerGetCustomer(&job->owner), job);
+        break;
+    case GNC_OWNER_VENDOR:
+        gncVendorRemoveJob (gncOwnerGetVendor(&job->owner), job);
+        break;
+    default:
+        break;
+    }
+
+    gncOwnerCopy (owner, &(job->owner));
+
+    switch (gncOwnerGetType (&(job->owner)))
+    {
+    case GNC_OWNER_CUSTOMER:
+        gncCustomerAddJob (gncOwnerGetCustomer(&job->owner), job);
+        break;
+    case GNC_OWNER_VENDOR:
+        gncVendorAddJob (gncOwnerGetVendor(&job->owner), job);
+        break;
+    default:
+        break;
+    }
+
+    mark_job (job);
+    gncJobCommitEdit (job);
+}
+
+void gncJobSetActive (GncJob *job, gboolean active)
+{
+    if (!job) return;
+    if (active == job->active) return;
+    gncJobBeginEdit (job);
+    job->active = active;
+    mark_job (job);
+    gncJobCommitEdit (job);
+}
+
+static void
+qofJobSetOwner (GncJob *job, QofInstance *ent)
+{
+    if (!job || !ent)
+    {
+        return;
+    }
+    qof_begin_edit(&job->inst);
+    qofOwnerSetEntity(&job->owner, ent);
+    mark_job (job);
+    qof_commit_edit(&job->inst);
+}
+
+void gncJobBeginEdit (GncJob *job)
+{
+    qof_begin_edit(&job->inst);
+}
+
+static void gncJobOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("Job QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void job_free (QofInstance *inst)
+{
+    GncJob *job = (GncJob *)inst;
+    gncJobFree (job);
+}
+
+static void gncJobOnDone (QofInstance *qof) { }
+
+void gncJobCommitEdit (GncJob *job)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(job))) return;
+    qof_commit_edit_part2 (&job->inst, gncJobOnError,
+                           gncJobOnDone, job_free);
+}
+
+/* ================================================================== */
+/* Get Functions */
+
+const char * gncJobGetID (const GncJob *job)
+{
+    if (!job) return NULL;
+    return job->id;
+}
+
+const char * gncJobGetName (const GncJob *job)
+{
+    if (!job) return NULL;
+    return job->name;
+}
+
+const char * gncJobGetReference (const GncJob *job)
+{
+    if (!job) return NULL;
+    return job->desc;
+}
+
+GncOwner * gncJobGetOwner (GncJob *job)
+{
+    if (!job) return NULL;
+    return &(job->owner);
+}
+
+gboolean gncJobGetActive (const GncJob *job)
+{
+    if (!job) return FALSE;
+    return job->active;
+}
+
+static QofInstance*
+qofJobGetOwner (GncJob *job)
+{
+    if (!job)
+    {
+        return NULL;
+    }
+    return QOF_INSTANCE(qofOwnerGetOwner(&job->owner));
+}
+
+/* Other functions */
+
+int gncJobCompare (const GncJob * a, const GncJob *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    return (safe_strcmp(a->id, b->id));
+}
+
+gboolean gncJobEqual(const GncJob * a, const GncJob *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
+    g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("Names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->desc, b->desc) != 0)
+    {
+        PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+    /* FIXME: Need real tests */
+#if 0
+    GncOwner      owner;
+#endif
+
+    return TRUE;
+}
+
+/* ================================================================== */
+/* Package-Private functions */
+
+static const char * _gncJobPrintable (gpointer item)
+{
+    GncJob *c;
+    if (!item) return NULL;
+    c = item;
+    return c->name;
+}
+
+static QofObject gncJobDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Job",
+    DI(.create            = ) (gpointer)gncJobCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) _gncJobPrintable,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncJobRegister (void)
+{
+    static QofParam params[] =
+    {
+        { JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, (QofSetterFunc)gncJobSetID },
+        { JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, (QofSetterFunc)gncJobSetName },
+        { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive },
+        { JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, (QofSetterFunc)gncJobSetReference },
+#ifdef GNUCASH_MAJOR_VERSION
+        { JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL },
+#else
+        { JOB_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofJobGetOwner, (QofSetterFunc)qofJobSetOwner },
+#endif
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    if (!qof_choice_create(GNC_ID_JOB))
+    {
+        return FALSE;
+    }
+    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_JOB, INVOICE_OWNER))
+    {
+        return FALSE;
+    }
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
+#ifdef GNUCASH_MAJOR_VERSION
+    qofJobGetOwner(NULL);
+    qofJobSetOwner(NULL, NULL);
+#endif
+    return qof_object_register (&gncJobDesc);
+}
+
+gint64 gncJobNextID (QofBook *book)
+{
+    return qof_book_get_counter (book, _GNC_MOD_NAME);
+}

Copied: gnucash/trunk/src/engine/gncJob.h (from rev 19328, gnucash/trunk/src/business/business-core/gncJob.h)
===================================================================
--- gnucash/trunk/src/engine/gncJob.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncJob.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,118 @@
+/********************************************************************\
+ * gncJob.h -- the Core Job Interface                               *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Job
+    @{ */
+/** @file gncJob.h
+    @brief  Job Interface
+    @author Copyright (C) 2001, 2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_JOB_H_
+#define GNC_JOB_H_
+
+typedef struct _gncJob GncJob;
+typedef struct _gncJobClass GncJobClass;
+
+#include "gncAddress.h"
+#include "gncOwner.h"
+
+#define GNC_ID_JOB "gncJob"
+
+/* --- type macros --- */
+#define GNC_TYPE_JOB            (gnc_job_get_type ())
+#define GNC_JOB(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_JOB, GncJob))
+#define GNC_JOB_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_JOB, GncJobClass))
+#define GNC_IS_JOB(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_JOB))
+#define GNC_IS_JOB_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_JOB))
+#define GNC_JOB_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_JOB, GncJobClass))
+GType gnc_job_get_type(void);
+
+/* Create/Destroy Functions */
+
+GncJob *gncJobCreate (QofBook *book);
+void gncJobDestroy (GncJob *job);
+
+/** \name Set Functions
+@{
+*/
+
+void gncJobSetID (GncJob *job, const char *id);
+void gncJobSetName (GncJob *job, const char *jobname);
+void gncJobSetReference (GncJob *job, const char *owner_reference);
+void gncJobSetOwner (GncJob *job, GncOwner *owner);
+void gncJobSetActive (GncJob *job, gboolean active);
+
+/** @} */
+void gncJobBeginEdit (GncJob *job);
+void gncJobCommitEdit (GncJob *job);
+
+/** \name Get Functions
+@{
+*/
+
+const char * gncJobGetID (const GncJob *job);
+const char * gncJobGetName (const GncJob *job);
+const char * gncJobGetReference (const GncJob *job);
+GncOwner * gncJobGetOwner (GncJob *job);
+
+/** @} */
+gboolean gncJobGetActive (const GncJob *job);
+
+/** Return a pointer to the instance gncJob that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncJob * gncJobLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncJob * gncJobLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_JOB, GncJob);
+}
+
+/* Other functions */
+
+int gncJobCompare (const GncJob *a, const GncJob *b);
+gboolean gncJobEqual(const GncJob *a, const GncJob *b);
+
+#define JOB_ID		"id"
+#define JOB_NAME	"name"
+#define JOB_REFERENCE	"reference"
+#define JOB_OWNER	"owner"
+#define Q_JOB_OWNER "owner_collection"
+#define JOB_ACTIVE	"active"
+
+/** deprecated functions */
+#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
+#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+#define gncJobRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
+#define gncJobLookupDirect(G,B) gncJobLookup((B),&(G))
+
+#endif /* GNC_JOB_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncJobP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncJobP.h)
===================================================================
--- gnucash/trunk/src/engine/gncJobP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncJobP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,58 @@
+/********************************************************************\
+ * gncJobP.h -- the Core Job Interface                              *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_JOBP_H_
+#define GNC_JOBP_H_
+
+#include "gncJob.h"
+
+gboolean gncJobRegister (void);
+gint64 gncJobNextID (QofBook *book);
+
+/** The gncCloneTaxTable() routine makes a copy of the indicated
+ *  tax table, placing it in the indicated book.  It copies
+ *  the id, name description and owner.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+GncJob * gncCloneJob (GncJob *from, QofBook *book);
+
+/** The gncJobObtainTwin() will find the 'twin' of the
+ *  indicated job in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneJob()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncJob * gncJobObtainTwin (GncJob *from, QofBook *book);
+
+#define gncJobSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+#endif /* GNC_JOBP_H_ */

Copied: gnucash/trunk/src/engine/gncOrder.c (from rev 19328, gnucash/trunk/src/business/business-core/gncOrder.c)
===================================================================
--- gnucash/trunk/src/engine/gncOrder.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOrder.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,610 @@
+/********************************************************************\
+ * gncOrder.c -- the Core Business Order                            *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001,2002 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "gncEntry.h"
+#include "gncEntryP.h"
+#include "gncOrder.h"
+#include "gncOrderP.h"
+#include "gncOwner.h"
+#include "gncOwnerP.h"
+
+struct _gncOrder
+{
+    QofInstance inst;
+
+    char *	id;
+    char *	notes;
+    gboolean 	active;
+
+    char *	reference;
+    char *	printname;
+    GncOwner	owner;
+    GList *	entries;
+    Timespec 	opened;
+    Timespec 	closed;
+};
+
+struct _gncOrderClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME	GNC_ID_ORDER
+
+#define SET_STR(obj, member, str) { \
+	char * tmp; \
+	\
+	if (!safe_strcmp (member, str)) return; \
+	gncOrderBeginEdit (obj); \
+	tmp = CACHE_INSERT (str); \
+	CACHE_REMOVE (member); \
+	member = tmp; \
+	}
+
+G_INLINE_FUNC void mark_order (GncOrder *order);
+void mark_order (GncOrder *order)
+{
+    qof_instance_set_dirty(&order->inst);
+    qof_event_gen (&order->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* =============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NOTES
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncOrder, gnc_order, QOF_TYPE_INSTANCE);
+
+static void
+gnc_order_init(GncOrder* order)
+{
+}
+
+static void
+gnc_order_dispose(GObject *orderp)
+{
+    G_OBJECT_CLASS(gnc_order_parent_class)->dispose(orderp);
+}
+
+static void
+gnc_order_finalize(GObject* orderp)
+{
+    G_OBJECT_CLASS(gnc_order_parent_class)->dispose(orderp);
+}
+
+static void
+gnc_order_get_property (GObject         *object,
+                        guint            prop_id,
+                        GValue          *value,
+                        GParamSpec      *pspec)
+{
+    GncOrder *order;
+
+    g_return_if_fail(GNC_IS_ORDER(object));
+
+    order = GNC_ORDER(object);
+    switch (prop_id)
+    {
+    case PROP_NOTES:
+        g_value_set_string(value, order->notes);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_order_set_property (GObject         *object,
+                        guint            prop_id,
+                        const GValue          *value,
+                        GParamSpec      *pspec)
+{
+    GncOrder *order;
+
+    g_return_if_fail(GNC_IS_ORDER(object));
+
+    order = GNC_ORDER(object);
+    switch (prop_id)
+    {
+    case PROP_NOTES:
+        gncOrderSetNotes(order, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    /* Refers to nothing */
+    return NULL;
+}
+
+static void
+gnc_order_class_init (GncOrderClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_order_dispose;
+    gobject_class->finalize = gnc_order_finalize;
+    gobject_class->set_property = gnc_order_set_property;
+    gobject_class->get_property = gnc_order_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = NULL;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NOTES,
+     g_param_spec_string ("name",
+                          "Order Notes",
+                          "The order notes is an arbitrary string "
+                          "assigned by the user to provide notes about "
+                          "this order.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncOrder *gncOrderCreate (QofBook *book)
+{
+    GncOrder *order;
+
+    if (!book) return NULL;
+
+    order = g_object_new (GNC_TYPE_ORDER, NULL);
+    qof_instance_init_data (&order->inst, _GNC_MOD_NAME, book);
+
+    order->id = CACHE_INSERT ("");
+    order->notes = CACHE_INSERT ("");
+    order->reference = CACHE_INSERT ("");
+
+    order->active = TRUE;
+
+    qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
+
+    return order;
+}
+
+void gncOrderDestroy (GncOrder *order)
+{
+    if (!order) return;
+    qof_instance_set_destroying(order, TRUE);
+    gncOrderCommitEdit (order);
+}
+
+static void gncOrderFree (GncOrder *order)
+{
+    if (!order) return;
+
+    qof_event_gen (&order->inst, QOF_EVENT_DESTROY, NULL);
+
+    g_list_free (order->entries);
+    CACHE_REMOVE (order->id);
+    CACHE_REMOVE (order->notes);
+    CACHE_REMOVE (order->reference);
+
+    if (order->printname) g_free (order->printname);
+
+    /* qof_instance_release (&order->inst); */
+    g_object_unref (order);
+}
+
+GncOrder *
+gncCloneOrder (GncOrder *from, QofBook *book)
+{
+    GList *node;
+    GncOrder *order;
+
+    if (!book) return NULL;
+
+    order = g_object_new (GNC_TYPE_ORDER, NULL);
+    qof_instance_init_data (&order->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&order->inst, &from->inst);
+
+    order->id = CACHE_INSERT (from->id);
+    order->notes = CACHE_INSERT (from->notes);
+    order->reference = CACHE_INSERT (from->reference);
+
+    order->active = from->active;
+    order->printname = NULL; /* yes, null, that's right */
+    order->opened = from->opened;
+    order->closed = from->closed;
+
+    order->owner = gncCloneOwner (&from->owner, book);
+
+    order->entries = NULL;
+    for (node = g_list_last(from->entries); node; node = node->prev)
+    {
+        GncEntry *entry = node->data;
+        entry = gncEntryObtainTwin (entry, book);
+        order->entries = g_list_prepend (order->entries, entry);
+    }
+
+    qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
+
+    return order;
+}
+
+GncOrder *
+gncOrderObtainTwin (GncOrder *from, QofBook *book)
+{
+    GncOrder *order;
+    if (!book) return NULL;
+
+    order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!order)
+    {
+        order = gncCloneOrder (from, book);
+    }
+
+    return order;
+}
+
+/* =============================================================== */
+/* Set Functions */
+
+void gncOrderSetID (GncOrder *order, const char *id)
+{
+    if (!order || !id) return;
+    SET_STR (order, order->id, id);
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetOwner (GncOrder *order, GncOwner *owner)
+{
+    if (!order || !owner) return;
+    if (gncOwnerEqual (&order->owner, owner)) return;
+
+    gncOrderBeginEdit (order);
+    gncOwnerCopy (owner, &order->owner);
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetDateOpened (GncOrder *order, Timespec date)
+{
+    if (!order) return;
+    if (timespec_equal (&order->opened, &date)) return;
+    gncOrderBeginEdit (order);
+    order->opened = date;
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetDateClosed (GncOrder *order, Timespec date)
+{
+    if (!order) return;
+    if (timespec_equal (&order->closed, &date)) return;
+    gncOrderBeginEdit (order);
+    order->closed = date;
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetNotes (GncOrder *order, const char *notes)
+{
+    if (!order || !notes) return;
+    SET_STR (order, order->notes, notes);
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetReference (GncOrder *order, const char *reference)
+{
+    if (!order || !reference) return;
+    SET_STR (order, order->reference, reference);
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+void gncOrderSetActive (GncOrder *order, gboolean active)
+{
+    if (!order) return;
+    if (order->active == active) return;
+    gncOrderBeginEdit (order);
+    order->active = active;
+    mark_order (order);
+    gncOrderCommitEdit (order);
+}
+
+/* =============================================================== */
+/* Add an Entry to the Order */
+void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
+{
+    GncOrder *old;
+
+    if (!order || !entry) return;
+
+    old = gncEntryGetOrder (entry);
+    if (old == order) return;			/* I already own it */
+    if (old) gncOrderRemoveEntry (old, entry);
+
+    order->entries = g_list_insert_sorted (order->entries, entry,
+                                           (GCompareFunc)gncEntryCompare);
+
+    /* This will send out an event -- make sure we're attached */
+    gncEntrySetOrder (entry, order);
+    mark_order (order);
+}
+
+void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
+{
+    if (!order || !entry) return;
+
+    gncEntrySetOrder (entry, NULL);
+    order->entries = g_list_remove (order->entries, entry);
+    mark_order (order);
+}
+
+/* Get Functions */
+
+const char * gncOrderGetID (const GncOrder *order)
+{
+    if (!order) return NULL;
+    return order->id;
+}
+
+GncOwner * gncOrderGetOwner (GncOrder *order)
+{
+    if (!order) return NULL;
+    return &order->owner;
+}
+
+Timespec gncOrderGetDateOpened (const GncOrder *order)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!order) return ts;
+    return order->opened;
+}
+
+Timespec gncOrderGetDateClosed (const GncOrder *order)
+{
+    Timespec ts;
+    ts.tv_sec = 0;
+    ts.tv_nsec = 0;
+    if (!order) return ts;
+    return order->closed;
+}
+
+const char * gncOrderGetNotes (const GncOrder *order)
+{
+    if (!order) return NULL;
+    return order->notes;
+}
+
+const char * gncOrderGetReference (const GncOrder *order)
+{
+    if (!order) return NULL;
+    return order->reference;
+}
+
+gboolean gncOrderGetActive (const GncOrder *order)
+{
+    if (!order) return FALSE;
+    return order->active;
+}
+
+/* Get the list Entries */
+GList * gncOrderGetEntries (GncOrder *order)
+{
+    if (!order) return NULL;
+    return order->entries;
+}
+
+gboolean gncOrderIsClosed (const GncOrder *order)
+{
+    if (!order) return FALSE;
+    if (order->closed.tv_sec || order->closed.tv_nsec) return TRUE;
+    return FALSE;
+}
+
+/* =============================================================== */
+
+void gncOrderBeginEdit (GncOrder *order)
+{
+    qof_begin_edit(&order->inst);
+}
+
+static void gncOrderOnError (QofInstance *order, QofBackendError errcode)
+{
+    PERR("Order QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncOrderOnDone (QofInstance *order) {}
+
+static void order_free (QofInstance *inst)
+{
+    GncOrder *order = (GncOrder *) inst;
+    gncOrderFree (order);
+}
+
+void gncOrderCommitEdit (GncOrder *order)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(order))) return;
+    qof_commit_edit_part2 (&order->inst, gncOrderOnError,
+                           gncOrderOnDone, order_free);
+}
+
+int gncOrderCompare (const GncOrder *a, const GncOrder *b)
+{
+    int compare;
+
+    if (a == b) return 0;
+    if (!a && b) return -1;
+    if (a && !b) return 1;
+
+    compare = safe_strcmp (a->id, b->id);
+    if (compare) return compare;
+
+    compare = timespec_cmp (&(a->opened), &(b->opened));
+    if (compare) return compare;
+
+    compare = timespec_cmp (&(a->closed), &(b->closed));
+    if (compare) return compare;
+
+    return qof_instance_guid_compare(a, b);
+}
+
+gboolean gncOrderEqual(const GncOrder * a, const GncOrder *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_ORDER(a), FALSE);
+    g_return_val_if_fail(GNC_IS_ORDER(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->notes, b->notes) != 0)
+    {
+        PWARN("Notes differ: %s vs %s", a->notes, b->notes);
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->reference, b->reference) != 0)
+    {
+        PWARN("References differ: %s vs %s", a->reference, b->reference);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->printname, b->printname) != 0)
+    {
+        PWARN("printnames differ: %s vs %s", a->printname, b->printname);
+        return FALSE;
+    }
+
+    /* FIXME: Need real tests */
+#if 0
+    GncOwner	owner;
+    GList *	entries;
+    Timespec 	opened;
+    Timespec 	closed;
+#endif
+
+    return TRUE;
+}
+
+/* =========================================================== */
+/* Package-Private functions */
+
+static const char *
+_gncOrderPrintable (gpointer obj)
+{
+    GncOrder *order = obj;
+
+    g_return_val_if_fail (order, NULL);
+
+    if (qof_instance_get_dirty_flag(order) || order->printname == NULL)
+    {
+        if (order->printname) g_free (order->printname);
+
+        order->printname =
+            g_strdup_printf ("%s%s", order->id,
+                             gncOrderIsClosed (order) ? _(" (closed)") : "");
+    }
+
+    return order->printname;
+}
+
+static QofObject gncOrderDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Order",
+    DI(.create            = ) (gpointer)gncOrderCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) _gncOrderPrintable,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncOrderRegister (void)
+{
+    static QofParam params[] =
+    {
+        { ORDER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetID, (QofSetterFunc)gncOrderSetID },
+        { ORDER_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetReference, (QofSetterFunc)gncOrderSetReference },
+        { ORDER_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncOrderGetOwner, (QofSetterFunc)gncOrderSetOwner },
+        { ORDER_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateOpened, (QofSetterFunc)gncOrderSetDateOpened },
+        { ORDER_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed, NULL },
+        { ORDER_CLOSED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateClosed, (QofSetterFunc)gncOrderSetDateClosed },
+        { ORDER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetNotes, (QofSetterFunc)gncOrderSetNotes },
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderGetActive, (QofSetterFunc)gncOrderSetActive },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params);
+
+    return qof_object_register (&gncOrderDesc);
+}
+
+gint64 gncOrderNextID (QofBook *book)
+{
+    return qof_book_get_counter (book, _GNC_MOD_NAME);
+}

Copied: gnucash/trunk/src/engine/gncOrder.h (from rev 19328, gnucash/trunk/src/business/business-core/gncOrder.h)
===================================================================
--- gnucash/trunk/src/engine/gncOrder.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOrder.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,124 @@
+/********************************************************************\
+ * gncOrder.h -- the Core Business Order Interface                  *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/* NOTE: Removed from doxygen by warlord on 2004-05-07 because
+ * this module is not fully implemented at this time.
+ */
+/* @addtogroup Business
+    @{ */
+/* @addtogroup Order
+    @{ */
+/* @file gncOrder.h
+    @brief Business Order Interface
+    @author Copyright (C) 2001 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_ORDER_H_
+#define GNC_ORDER_H_
+
+typedef struct _gncOrder GncOrder;
+typedef struct _gncOrderClass GncOrderClass;
+
+#include "gncEntry.h"
+#include "gncOwner.h"
+#include "qof.h"
+
+#define GNC_ID_ORDER "gncOrder"
+
+/* --- type macros --- */
+#define GNC_TYPE_ORDER            (gnc_order_get_type ())
+#define GNC_ORDER(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_ORDER, GncOrder))
+#define GNC_ORDER_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_ORDER, GncOrderClass))
+#define GNC_IS_ORDER(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_ORDER))
+#define GNC_IS_ORDER_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_ORDER))
+#define GNC_ORDER_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ORDER, GncOrderClass))
+GType gnc_order_get_type(void);
+
+/* Create/Destroy Functions */
+
+GncOrder *gncOrderCreate (QofBook *book);
+void gncOrderDestroy (GncOrder *order);
+
+/* Set Functions */
+
+void gncOrderSetID (GncOrder *order, const char *id);
+void gncOrderSetOwner (GncOrder *order, GncOwner *owner);
+void gncOrderSetDateOpened (GncOrder *order, Timespec date);
+void gncOrderSetDateClosed (GncOrder *order, Timespec date);
+void gncOrderSetNotes (GncOrder *order, const char *notes);
+void gncOrderSetReference (GncOrder *order, const char *reference);
+void gncOrderSetActive (GncOrder *order, gboolean active);
+
+/* Add an Entry to the Order */
+void gncOrderAddEntry (GncOrder *order, GncEntry *entry);
+void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry);
+
+/* Get Functions */
+
+const char * gncOrderGetID (const GncOrder *order);
+GncOwner * gncOrderGetOwner (GncOrder *order);
+Timespec gncOrderGetDateOpened (const GncOrder *order);
+Timespec gncOrderGetDateClosed (const GncOrder *order);
+const char * gncOrderGetNotes (const GncOrder *order);
+const char * gncOrderGetReference (const GncOrder *order);
+gboolean gncOrderGetActive (const GncOrder *order);
+
+/* Get the list Entries */
+GList * gncOrderGetEntries (GncOrder *order);
+
+void gncOrderBeginEdit (GncOrder *order);
+void gncOrderCommitEdit (GncOrder *order);
+int gncOrderCompare (const GncOrder *a, const GncOrder *b);
+gboolean gncOrderEqual(const GncOrder *a, const GncOrder *b);
+
+gboolean gncOrderIsClosed (const GncOrder *order);
+
+/** Return a pointer to the instance gncOrder that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncOrder * gncOrderLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncOrder * gncOrderLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_ORDER, GncOrder);
+}
+
+#define ORDER_ID	"id"
+#define ORDER_REFERENCE	"reference"
+#define ORDER_OWNER	"owner"
+#define ORDER_OPENED	"date_opened"
+#define ORDER_CLOSED	"date_closed"
+#define ORDER_IS_CLOSED	"is_closed?"
+#define ORDER_NOTES	"notes"
+
+/** deprecated functions */
+#define gncOrderGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+#define gncOrderGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
+
+#endif /* GNC_ORDER_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncOrderP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncOrderP.h)
===================================================================
--- gnucash/trunk/src/engine/gncOrderP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOrderP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,59 @@
+/********************************************************************\
+ * gncOrderP.h -- the Core Busines Order Interface                  *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_ORDERP_H_
+#define GNC_ORDERP_H_
+
+#include "gncOrder.h"
+
+gboolean gncOrderRegister (void);
+gint64 gncOrderNextID (QofBook *book);
+
+/** The gncCloneOrder() routine makes a copy of the indicated
+ *  order, placing it in the indicated book.  It copies
+ *  the id, notes, reference, etc.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncOrder * gncCloneOrder (GncOrder *from, QofBook *);
+
+/** The gncOrderObtainTwin() will find the 'twin' of the
+ *  indicated order in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneOrder()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncOrder * gncOrderObtainTwin (GncOrder *from, QofBook *book);
+
+#define gncOrderSetGUID(O,G) qof_instance_set_guid(QOF_INSTANCE(O),(G))
+
+#endif /* GNC_ORDERP_H_ */

Copied: gnucash/trunk/src/engine/gncOwner.c (from rev 19328, gnucash/trunk/src/business/business-core/gncOwner.c)
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOwner.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,586 @@
+/********************************************************************\
+ * gncOwner.c -- Business Interface:  Object OWNERs                 *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001, 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+ * Copyright (c) 2006 David Hampton <hampton at employees.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>		/* for memcpy() */
+
+#include "gncCustomerP.h"
+#include "gncEmployeeP.h"
+#include "gncJobP.h"
+#include "gncOwner.h"
+#include "gncOwnerP.h"
+#include "gncVendorP.h"
+
+#define _GNC_MOD_NAME	GNC_ID_OWNER
+
+#define GNC_OWNER_ID	"gncOwner"
+#define GNC_OWNER_TYPE	"owner-type"
+#define GNC_OWNER_GUID	"owner-guid"
+
+GncOwner * gncOwnerCreate (void)
+{
+    GncOwner *o;
+
+    o = g_new0 (GncOwner, 1);
+    o->type = GNC_OWNER_NONE;
+    return o;
+}
+
+void gncOwnerDestroy (GncOwner *owner)
+{
+    if (!owner) return;
+    g_free (owner);
+}
+
+void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
+{
+    if (!owner) return;
+    owner->type = GNC_OWNER_UNDEFINED;
+    owner->owner.undefined = obj;
+}
+
+void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
+{
+    if (!owner) return;
+    owner->type = GNC_OWNER_CUSTOMER;
+    owner->owner.customer = customer;
+}
+
+void gncOwnerInitJob (GncOwner *owner, GncJob *job)
+{
+    if (!owner) return;
+    owner->type = GNC_OWNER_JOB;
+    owner->owner.job = job;
+}
+
+void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
+{
+    if (!owner) return;
+    owner->type = GNC_OWNER_VENDOR;
+    owner->owner.vendor = vendor;
+}
+
+void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee)
+{
+    if (!owner) return;
+    owner->type = GNC_OWNER_EMPLOYEE;
+    owner->owner.employee = employee;
+}
+
+GncOwnerType gncOwnerGetType (const GncOwner *owner)
+{
+    if (!owner) return GNC_OWNER_NONE;
+    return owner->type;
+}
+
+QofIdType
+qofOwnerGetType(const GncOwner *owner)
+{
+    QofIdType type;
+
+    type = NULL;
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE :
+    {
+        type = NULL;
+        break;
+    }
+    case GNC_OWNER_UNDEFINED :
+    {
+        type = NULL;
+        break;
+    }
+    case GNC_OWNER_CUSTOMER :
+    {
+        type = GNC_ID_CUSTOMER;
+        break;
+    }
+    case GNC_OWNER_JOB :
+    {
+        type = GNC_ID_JOB;
+        break;
+    }
+    case GNC_OWNER_VENDOR :
+    {
+        type = GNC_ID_VENDOR;
+        break;
+    }
+    case GNC_OWNER_EMPLOYEE :
+    {
+        type = GNC_ID_EMPLOYEE;
+        break;
+    }
+    }
+    return type;
+}
+
+QofInstance*
+qofOwnerGetOwner (const GncOwner *owner)
+{
+    QofInstance *ent;
+
+    if (!owner)
+    {
+        return NULL;
+    }
+    ent = NULL;
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE :
+    {
+        break;
+    }
+    case GNC_OWNER_UNDEFINED :
+    {
+        break;
+    }
+    case GNC_OWNER_CUSTOMER :
+    {
+        ent = QOF_INSTANCE(owner->owner.customer);
+        break;
+    }
+    case GNC_OWNER_JOB :
+    {
+        ent = QOF_INSTANCE(owner->owner.job);
+        break;
+    }
+    case GNC_OWNER_VENDOR :
+    {
+        ent = QOF_INSTANCE(owner->owner.vendor);
+        break;
+    }
+    case GNC_OWNER_EMPLOYEE :
+    {
+        ent = QOF_INSTANCE(owner->owner.employee);
+        break;
+    }
+    }
+    return ent;
+}
+
+void
+qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
+{
+    if (!owner || !ent)
+    {
+        return;
+    }
+    if (0 == safe_strcmp(ent->e_type, GNC_ID_CUSTOMER))
+    {
+        owner->type = GNC_OWNER_CUSTOMER;
+        gncOwnerInitCustomer(owner, (GncCustomer*)ent);
+    }
+    if (0 == safe_strcmp(ent->e_type, GNC_ID_JOB))
+    {
+        owner->type = GNC_OWNER_JOB;
+        gncOwnerInitJob(owner, (GncJob*)ent);
+    }
+    if (0 == safe_strcmp(ent->e_type, GNC_ID_VENDOR))
+    {
+        owner->type = GNC_OWNER_VENDOR;
+        gncOwnerInitVendor(owner, (GncVendor*)ent);
+    }
+    if (0 == safe_strcmp(ent->e_type, GNC_ID_EMPLOYEE))
+    {
+        owner->type = GNC_OWNER_EMPLOYEE;
+        gncOwnerInitEmployee(owner, (GncEmployee*)ent);
+    }
+}
+
+gpointer gncOwnerGetUndefined (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    if (owner->type != GNC_OWNER_UNDEFINED) return NULL;
+    return owner->owner.undefined;
+}
+
+GncCustomer * gncOwnerGetCustomer (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    if (owner->type != GNC_OWNER_CUSTOMER) return NULL;
+    return owner->owner.customer;
+}
+
+GncJob * gncOwnerGetJob (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    if (owner->type != GNC_OWNER_JOB) return NULL;
+    return owner->owner.job;
+}
+
+GncVendor * gncOwnerGetVendor (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    if (owner->type != GNC_OWNER_VENDOR) return NULL;
+    return owner->owner.vendor;
+}
+
+GncEmployee * gncOwnerGetEmployee (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    if (owner->type != GNC_OWNER_EMPLOYEE) return NULL;
+    return owner->owner.employee;
+}
+
+gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE:
+    case GNC_OWNER_UNDEFINED:
+    default:
+        return NULL;
+    case GNC_OWNER_CUSTOMER:
+        return gncCustomerGetCurrency (owner->owner.customer);
+    case GNC_OWNER_VENDOR:
+        return gncVendorGetCurrency (owner->owner.vendor);
+    case GNC_OWNER_EMPLOYEE:
+        return gncEmployeeGetCurrency (owner->owner.employee);
+    case GNC_OWNER_JOB:
+        return gncOwnerGetCurrency (gncJobGetOwner (owner->owner.job));
+    }
+}
+
+void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
+{
+    if (!src || !dest) return;
+    if (src == dest) return;
+    memcpy (dest, src, sizeof (*dest));
+}
+
+GncOwner
+gncCloneOwner (const GncOwner *from, QofBook *book)
+{
+    GncOwner owner = { GNC_OWNER_NONE };
+    if (!from) return owner;
+    owner.type = from->type;
+    switch (from->type)
+    {
+    case GNC_OWNER_NONE:
+        return owner;
+    case GNC_OWNER_UNDEFINED:
+        owner.owner.undefined = from->owner.undefined;  /* XXX probably wrong ! */
+        return owner;
+    case GNC_OWNER_CUSTOMER:
+        owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book);
+        return owner;
+    case GNC_OWNER_JOB:
+        owner.owner.job = gncJobObtainTwin (from->owner.job, book);
+        return owner;
+    case GNC_OWNER_VENDOR:
+        owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book);
+        return owner;
+    case GNC_OWNER_EMPLOYEE:
+        owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book);
+        return owner;
+    default:
+        return owner;
+    }
+}
+
+gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
+{
+    if (!a || !b) return FALSE;
+    if (gncOwnerGetType (a) != gncOwnerGetType (b)) return FALSE;
+    return (a->owner.undefined == b->owner.undefined);
+}
+
+const char * gncOwnerGetName (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE:
+    case GNC_OWNER_UNDEFINED:
+    default:
+        return NULL;
+    case GNC_OWNER_CUSTOMER:
+        return gncCustomerGetName (owner->owner.customer);
+    case GNC_OWNER_JOB:
+        return gncJobGetName (owner->owner.job);
+    case GNC_OWNER_VENDOR:
+        return gncVendorGetName (owner->owner.vendor);
+    case GNC_OWNER_EMPLOYEE:
+        return gncAddressGetName(gncEmployeeGetAddr (owner->owner.employee));
+    }
+}
+
+const GncGUID * gncOwnerGetGUID (const GncOwner *owner)
+{
+    if (!owner) return NULL;
+
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE:
+    case GNC_OWNER_UNDEFINED:
+    default:
+        return NULL;
+    case GNC_OWNER_CUSTOMER:
+        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer));
+    case GNC_OWNER_JOB:
+        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job));
+    case GNC_OWNER_VENDOR:
+        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor));
+    case GNC_OWNER_EMPLOYEE:
+        return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee));
+    }
+}
+
+GncGUID gncOwnerRetGUID (GncOwner *owner)
+{
+    const GncGUID *guid = gncOwnerGetGUID (owner);
+    if (guid)
+        return *guid;
+    return *guid_null ();
+}
+
+GncOwner * gncOwnerGetEndOwner (GncOwner *owner)
+{
+    if (!owner) return NULL;
+    switch (owner->type)
+    {
+    case GNC_OWNER_NONE:
+    case GNC_OWNER_UNDEFINED:
+    default:
+        return NULL;
+    case GNC_OWNER_CUSTOMER:
+    case GNC_OWNER_VENDOR:
+    case GNC_OWNER_EMPLOYEE:
+        return owner;
+    case GNC_OWNER_JOB:
+        return gncJobGetOwner (owner->owner.job);
+    }
+}
+
+int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    if (a->type != b->type)
+        return (a->type - b->type);
+
+    switch (a->type)
+    {
+    case GNC_OWNER_NONE:
+    case GNC_OWNER_UNDEFINED:
+    default:
+        return 0;
+    case GNC_OWNER_CUSTOMER:
+        return gncCustomerCompare (a->owner.customer, b->owner.customer);
+    case GNC_OWNER_VENDOR:
+        return gncVendorCompare (a->owner.vendor, b->owner.vendor);
+    case GNC_OWNER_EMPLOYEE:
+        return gncEmployeeCompare (a->owner.employee, b->owner.employee);
+    case GNC_OWNER_JOB:
+        return gncJobCompare (a->owner.job, b->owner.job);
+    }
+}
+
+const GncGUID * gncOwnerGetEndGUID (GncOwner *owner)
+{
+    if (!owner) return NULL;
+    owner = gncOwnerGetEndOwner (owner);
+    return gncOwnerGetGUID (owner);
+}
+
+void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+
+    if (!owner || !lot)
+        return;
+
+    kvp = gnc_lot_get_slots (lot);
+
+    value = kvp_value_new_gint64 (gncOwnerGetType (owner));
+    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
+    kvp_value_delete (value);
+
+    value = kvp_value_new_guid (gncOwnerGetGUID (owner));
+    kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
+    kvp_value_delete (value);
+
+}
+
+gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
+{
+    KvpFrame *kvp;
+    KvpValue *value;
+    GncGUID *guid;
+    QofBook *book;
+    GncOwnerType type;
+
+    if (!lot || !owner) return FALSE;
+
+    book = gnc_lot_get_book (lot);
+    kvp = gnc_lot_get_slots (lot);
+
+    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
+    if (!value) return FALSE;
+
+    type = kvp_value_get_gint64 (value);
+
+    value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
+    if (!value) return FALSE;
+
+    guid = kvp_value_get_guid (value);
+    if (!guid)
+        return FALSE;
+
+    switch (type)
+    {
+    case GNC_OWNER_CUSTOMER:
+        gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
+        break;
+    case GNC_OWNER_VENDOR:
+        gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
+        break;
+    case GNC_OWNER_EMPLOYEE:
+        gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
+        break;
+    case GNC_OWNER_JOB:
+        gncOwnerInitJob (owner, gncJobLookup (book, guid));
+        break;
+    default:
+        return FALSE;
+    }
+
+    return (owner->owner.undefined != NULL);
+}
+
+gboolean gncOwnerIsValid (const GncOwner *owner)
+{
+    if (!owner) return FALSE;
+    return (owner->owner.undefined != NULL);
+}
+
+KvpFrame* gncOwnerGetSlots(GncOwner* owner)
+{
+    if (!owner) return NULL;
+
+    switch (gncOwnerGetType(owner))
+    {
+    case GNC_OWNER_CUSTOMER:
+    case GNC_OWNER_VENDOR:
+    case GNC_OWNER_EMPLOYEE:
+        return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined));
+    case GNC_OWNER_JOB:
+        return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner)));
+    default:
+        return NULL;
+    }
+}
+
+/* XXX: Yea, this is broken, but it should work fine for Queries.
+ * We're single-threaded, right?
+ */
+static GncOwner *
+owner_from_lot (GNCLot *lot)
+{
+    static GncOwner owner;
+
+    if (!lot) return NULL;
+    if (gncOwnerGetOwnerFromLot (lot, &owner))
+        return &owner;
+
+    return NULL;
+}
+
+static void
+reg_lot (void)
+{
+    static QofParam params[] =
+    {
+        { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL },
+        { NULL },
+    };
+
+    qof_class_register (GNC_ID_LOT, NULL, params);
+}
+
+gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid)
+{
+    if (!book || !owner || !type || !guid) return FALSE;
+
+    if (0 == safe_strcmp(type, GNC_ID_CUSTOMER))
+    {
+        GncCustomer *customer = gncCustomerLookup(book, guid);
+        gncOwnerInitCustomer(owner, customer);
+        return (NULL != customer);
+    }
+    else if (0 == safe_strcmp(type, GNC_ID_JOB))
+    {
+        GncJob *job = gncJobLookup(book, guid);
+        gncOwnerInitJob(owner, job);
+        return (NULL != job);
+    }
+    else if (0 == safe_strcmp(type, GNC_ID_VENDOR))
+    {
+        GncVendor *vendor = gncVendorLookup(book, guid);
+        gncOwnerInitVendor(owner, vendor);
+        return (NULL != vendor);
+    }
+    else if (0 == safe_strcmp(type, GNC_ID_EMPLOYEE))
+    {
+        GncEmployee *employee = gncEmployeeLookup(book, guid);
+        gncOwnerInitEmployee(owner, employee);
+        return (NULL != employee);
+    }
+    return 0;
+}
+
+gboolean gncOwnerRegister (void)
+{
+    static QofParam params[] =
+    {
+        { OWNER_TYPE, QOF_TYPE_INT64,      (QofAccessFunc)gncOwnerGetType,          NULL },
+        { OWNER_CUSTOMER, GNC_ID_CUSTOMER, (QofAccessFunc)gncOwnerGetCustomer,      NULL },
+        { OWNER_JOB, GNC_ID_JOB,           (QofAccessFunc)gncOwnerGetJob,           NULL },
+        { OWNER_VENDOR, GNC_ID_VENDOR,     (QofAccessFunc)gncOwnerGetVendor,        NULL },
+        { OWNER_EMPLOYEE, GNC_ID_EMPLOYEE, (QofAccessFunc)gncOwnerGetEmployee,      NULL },
+        { OWNER_PARENT, GNC_ID_OWNER,      (QofAccessFunc)gncOwnerGetEndOwner,      NULL },
+        { OWNER_PARENTG, QOF_TYPE_GUID,    (QofAccessFunc)gncOwnerGetEndGUID,       NULL },
+        { OWNER_NAME, QOF_TYPE_STRING,     (QofAccessFunc)gncOwnerGetName, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID,   (QofAccessFunc)gncOwnerGetGUID, NULL },
+        { NULL },
+    };
+
+    qof_class_register (GNC_ID_OWNER, (QofSortFunc)gncOwnerCompare, params);
+    reg_lot ();
+
+    return TRUE;
+}

Copied: gnucash/trunk/src/engine/gncOwner.h (from rev 19328, gnucash/trunk/src/business/business-core/gncOwner.h)
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOwner.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,169 @@
+/********************************************************************\
+ * gncOwner.h -- Business Interface:  Object OWNERs                 *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Owner
+    @{ */
+/** @file gncOwner.h
+    @brief Business Interface:  Object OWNERs
+    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
+    @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+    @author Copyright (c) 2006 David Hampton <hampton at employees.org>
+*/
+
+#ifndef GNC_OWNER_H_
+#define GNC_OWNER_H_
+
+typedef struct _gncOwner GncOwner;
+
+#define GNC_ID_OWNER   "gncOwner"
+
+#include "qof.h"
+#include "gncCustomer.h"
+#include "gncJob.h"
+#include "gncVendor.h"
+#include "gncEmployee.h"
+#include "gnc-lot.h"
+
+typedef enum
+{
+    GNC_OWNER_NONE ,
+    GNC_OWNER_UNDEFINED ,
+    GNC_OWNER_CUSTOMER ,
+    GNC_OWNER_JOB ,
+    GNC_OWNER_VENDOR ,
+    GNC_OWNER_EMPLOYEE ,
+} GncOwnerType;
+
+/** \name QOF handling
+
+Whilst GncOwner is not a formal QOF object, these functions
+are still expected to be useful in making GncOwner transparent
+to QOF as they can be used by objects like GncInvoice.
+@{
+*/
+/** return the type for the collection. */
+QofIdType qofOwnerGetType(const GncOwner *owner);
+/** return the owner itself as an entity. */
+QofInstance* qofOwnerGetOwner (const GncOwner *owner);
+/** set the owner from the entity. */
+void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
+
+gboolean
+gncOwnerRegister(void);
+
+/** @} */
+
+#ifndef SWIG
+
+/** \struct GncOwner */
+struct _gncOwner
+{
+    GncOwnerType     type;      /**< Customer, Job, Vendor, Employee or Undefined. */
+    union
+    {
+        gpointer       undefined;
+        GncCustomer *  customer;
+        GncJob *       job;
+        GncVendor *    vendor;
+        GncEmployee *  employee;
+    } owner;                   /**< holds the pointer to the owner object. */
+    gpointer         qof_temp; /**< Set type independently of the owner. */
+};
+
+#endif /* SWIG */
+
+/** \name Setup routines
+@{
+*/
+void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
+void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
+void gncOwnerInitJob (GncOwner *owner, GncJob *job);
+void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
+void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee);
+/** @} */
+/** \name Get routines.
+@{
+*/
+GncOwnerType gncOwnerGetType (const GncOwner *owner);
+gpointer gncOwnerGetUndefined (const GncOwner *owner);
+GncCustomer * gncOwnerGetCustomer (const GncOwner *owner);
+GncJob * gncOwnerGetJob (const GncOwner *owner);
+GncVendor * gncOwnerGetVendor (const GncOwner *owner);
+GncEmployee * gncOwnerGetEmployee (const GncOwner *owner);
+/** @} */
+void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
+gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
+int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
+
+const char * gncOwnerGetName (const GncOwner *owner);
+gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
+
+/** Get the GncGUID of the immediate owner */
+const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
+GncGUID gncOwnerRetGUID (GncOwner *owner);
+
+gboolean gncOwnerIsValid (const GncOwner *owner);
+
+/**
+ * Get the "parent" Owner or GncGUID thereof.  The "parent" owner
+ * is the Customer or Vendor, or the Owner of a Job
+ */
+GncOwner * gncOwnerGetEndOwner (GncOwner *owner);
+const GncGUID * gncOwnerGetEndGUID (GncOwner *owner);
+
+/** attach an owner to a lot */
+void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
+
+/** Get the owner from the lot.  If an owner is found in the lot,
+ * fill in "owner" and return TRUE.  Otherwise return FALSE.
+ */
+gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
+
+gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
+
+/** Get the kvp-frame from the underlying owner object */
+KvpFrame* gncOwnerGetSlots(GncOwner* owner);
+
+#define OWNER_TYPE        "type"
+#define OWNER_TYPE_STRING "type-string"  /**< Allows the type to be handled externally. */
+#define OWNER_CUSTOMER    "customer"
+#define OWNER_JOB         "job"
+#define OWNER_VENDOR      "vendor"
+#define OWNER_EMPLOYEE    "employee"
+#define OWNER_PARENT      "parent"
+#define OWNER_PARENTG     "parent-guid"
+#define OWNER_NAME        "name"
+
+#define OWNER_FROM_LOT    "owner-from-lot"
+
+/**
+ * These two functions are mainly for the convenience of scheme code.
+ * Normal C code has no need to ever use these two functions, and rather
+ * can just use a GncOwner directly and just pass around a pointer to it.
+ */
+GncOwner * gncOwnerCreate (void);
+void gncOwnerDestroy (GncOwner *owner);
+
+#endif /* GNC_OWNER_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncOwnerP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncOwnerP.h)
===================================================================
--- gnucash/trunk/src/engine/gncOwnerP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncOwnerP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,40 @@
+/********************************************************************\
+ * gncOwnerP.h -- Business Interface:  Object OWNERs private file   *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001, 2002 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_OWNERP_H_
+#define GNC_OWNERP_H_
+
+#include "gncOwner.h"
+
+gboolean gncOwnerRegister (void);
+
+/** The gncCloneOwner() routine makes a copy of the indicated
+ *  owner union structure.
+ */
+GncOwner gncCloneOwner (const GncOwner *from, QofBook *);
+
+#endif /* GNC_OWNERP_H_ */

Copied: gnucash/trunk/src/engine/gncTaxTable.c (from rev 19328, gnucash/trunk/src/business/business-core/gncTaxTable.c)
===================================================================
--- gnucash/trunk/src/engine/gncTaxTable.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncTaxTable.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,1075 @@
+/********************************************************************\
+ * gncTaxTable.c -- the Gnucash Tax Table interface                 *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "gncTaxTableP.h"
+
+struct _gncTaxTable
+{
+    QofInstance     inst;
+    char *          name;
+    GncTaxTableEntryList*  entries;
+    Timespec        modtime;      /* internal date of last modtime */
+
+    /* See src/doc/business.txt for an explanation of the following */
+    /* Code that handles this is *identical* to that in gncBillTerm */
+    gint64          refcount;
+    GncTaxTable *   parent;       /* if non-null, we are an immutable child */
+    GncTaxTable *   child;        /* if non-null, we have not changed */
+    gboolean        invisible;
+    GList *         children;     /* list of children for disconnection */
+};
+
+struct _gncTaxTableClass
+{
+    QofInstanceClass parent_class;
+};
+
+struct _gncTaxTableEntry
+{
+    GncTaxTable *   table;
+    Account *       account;
+    GncAmountType   type;
+    gnc_numeric     amount;
+};
+
+struct _book_info
+{
+    GList *         tables;          /* visible tables */
+};
+
+static GncTaxTableEntry * CloneTaxEntry (const GncTaxTableEntry*, QofBook *);
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+/* =============================================================== */
+/* You must edit the functions in this block in tandem.  KEEP THEM IN
+   SYNC! */
+
+#define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);
+const char *
+gncAmountTypeToString (GncAmountType type)
+{
+    switch (type)
+    {
+        GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_VALUE, "VALUE");
+        GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_PERCENT, "PERCENT");
+    default:
+        g_warning ("asked to translate unknown amount type %d.\n", type);
+        break;
+    }
+    return(NULL);
+}
+
+const char *
+gncTaxIncludedTypeToString (GncTaxIncluded type)
+{
+    switch (type)
+    {
+        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_YES, "YES");
+        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_NO, "NO");
+        GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_USEGLOBAL, "USEGLOBAL");
+    default:
+        g_warning ("asked to translate unknown taxincluded type %d.\n", type);
+        break;
+    }
+    return(NULL);
+}
+#undef GNC_RETURN_ENUM_AS_STRING
+#define GNC_RETURN_ON_MATCH(s,x) \
+  if(safe_strcmp((s), (str)) == 0) { *type = x; return(TRUE); }
+gboolean
+gncAmountStringToType (const char *str, GncAmountType *type)
+{
+    GNC_RETURN_ON_MATCH ("VALUE", GNC_AMT_TYPE_VALUE);
+    GNC_RETURN_ON_MATCH ("PERCENT", GNC_AMT_TYPE_PERCENT);
+    g_warning ("asked to translate unknown amount type string %s.\n",
+               str ? str : "(null)");
+
+    return(FALSE);
+}
+
+gboolean
+gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type)
+{
+    GNC_RETURN_ON_MATCH ("YES", GNC_TAXINCLUDED_YES);
+    GNC_RETURN_ON_MATCH ("NO", GNC_TAXINCLUDED_NO);
+    GNC_RETURN_ON_MATCH ("USEGLOBAL", GNC_TAXINCLUDED_USEGLOBAL);
+    g_warning ("asked to translate unknown taxincluded type string %s.\n",
+               str ? str : "(null)");
+
+    return(FALSE);
+}
+#undef GNC_RETURN_ON_MATCH
+
+/* =============================================================== */
+/* Misc inline functions */
+
+#define _GNC_MOD_NAME        GNC_ID_TAXTABLE
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncTaxTableBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+static inline void
+mark_table (GncTaxTable *table)
+{
+    qof_instance_set_dirty(&table->inst);
+    qof_event_gen (&table->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+static inline void
+maybe_resort_list (GncTaxTable *table)
+{
+    struct _book_info *bi;
+
+    if (table->parent || table->invisible) return;
+    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
+    bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare);
+}
+
+static inline void
+mod_table (GncTaxTable *table)
+{
+    timespecFromTime_t (&table->modtime, time(NULL));
+}
+
+static inline void addObj (GncTaxTable *table)
+{
+    struct _book_info *bi;
+    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
+    bi->tables = g_list_insert_sorted (bi->tables, table,
+                                       (GCompareFunc)gncTaxTableCompare);
+}
+
+static inline void remObj (GncTaxTable *table)
+{
+    struct _book_info *bi;
+    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
+    bi->tables = g_list_remove (bi->tables, table);
+}
+
+static inline void
+gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
+{
+    g_return_if_fail(table);
+    g_return_if_fail(child);
+    g_return_if_fail(qof_instance_get_destroying(table) == FALSE);
+
+    table->children = g_list_prepend(table->children, child);
+}
+
+static inline void
+gncTaxTableRemoveChild (GncTaxTable *table, const GncTaxTable *child)
+{
+    g_return_if_fail(table);
+    g_return_if_fail(child);
+
+    if (qof_instance_get_destroying(table)) return;
+
+    table->children = g_list_remove(table->children, child);
+}
+
+/* =============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncTaxTable, gnc_taxtable, QOF_TYPE_INSTANCE);
+
+static void
+gnc_taxtable_init(GncTaxTable* tt)
+{
+}
+
+static void
+gnc_taxtable_dispose(GObject *ttp)
+{
+    G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
+}
+
+static void
+gnc_taxtable_finalize(GObject* ttp)
+{
+    G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
+}
+
+static void
+gnc_taxtable_get_property (GObject         *object,
+                           guint            prop_id,
+                           GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncTaxTable *tt;
+
+    g_return_if_fail(GNC_IS_TAXTABLE(object));
+
+    tt = GNC_TAXTABLE(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, tt->name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_taxtable_set_property (GObject         *object,
+                           guint            prop_id,
+                           const GValue          *value,
+                           GParamSpec      *pspec)
+{
+    GncTaxTable *tt;
+
+    g_return_if_fail(GNC_IS_TAXTABLE(object));
+
+    tt = GNC_TAXTABLE(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncTaxTableSetName(tt, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncTaxTable* tt;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
+
+    tt = GNC_TAXTABLE(inst);
+    return g_strdup_printf("Tax table %s", tt->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncTaxTable* tt;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
+
+    tt = GNC_TAXTABLE(inst);
+
+    if (GNC_IS_ACCOUNT(ref))
+    {
+        GList* node;
+
+        for (node = tt->entries; node != NULL; node = node->next)
+        {
+            GncTaxTableEntry* tte = node->data;
+
+            if (tte->account == GNC_ACCOUNT(ref))
+            {
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_ACCOUNT(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_taxtable_class_init (GncTaxTableClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_taxtable_dispose;
+    gobject_class->finalize = gnc_taxtable_finalize;
+    gobject_class->set_property = gnc_taxtable_set_property;
+    gobject_class->get_property = gnc_taxtable_get_property;
+
+    qof_class->get_display_name = impl_get_display_name;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "TaxTable Name",
+                          "The accountName is an arbitrary string "
+                          "assigned by the user.  It is intended to "
+                          "a short, 10 to 30 character long string "
+                          "that is displayed by the GUI as the "
+                          "tax table mnemonic.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncTaxTable *
+gncTaxTableCreate (QofBook *book)
+{
+    GncTaxTable *table;
+    if (!book) return NULL;
+
+    table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
+    qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
+    table->name = CACHE_INSERT ("");
+    addObj (table);
+    qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
+    return table;
+}
+
+
+GncTaxTable *
+gncCloneTaxTable (GncTaxTable *from, QofBook *book)
+{
+    GList *node;
+    GncTaxTable *table;
+    if (!book) return NULL;
+
+    table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
+    qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&table->inst, &from->inst);
+
+    table->name = CACHE_INSERT (from->name);
+    table->modtime = from->modtime;
+    table->invisible = from->invisible;
+
+    table->refcount = 0;
+
+    /* Make copies of parents and children. Note that this can be
+     * a recursive copy ... treat as doubly-linked list. */
+    if (from->child)
+    {
+        table->child = gncTaxTableObtainTwin (from->child, book);
+        table->child->parent = table;
+    }
+    if (from->parent)
+    {
+        table->parent = gncTaxTableObtainTwin (from->parent, book);
+        table->parent->child = table;
+    }
+    for (node = g_list_last(from->children); node; node = node->next)
+    {
+        GncTaxTable *tbl = node->data;
+        tbl = gncTaxTableObtainTwin (tbl, book);
+        tbl->parent = table;
+        table->children = g_list_prepend(table->children, tbl);
+    }
+
+    /* Copy tax entries, preserving the order in the list */
+    table->entries = NULL;
+    for (node = g_list_last(from->entries); node; node = node->prev)
+    {
+        GncTaxTableEntry *ent = node->data;
+        ent = CloneTaxEntry (ent, book);
+        table->entries = g_list_prepend (table->entries, ent);
+    }
+
+    addObj (table);
+    qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
+    return table;
+}
+
+GncTaxTable *
+gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book)
+{
+    GncTaxTable *table;
+    if (!from) return NULL;
+
+    table = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!table)
+    {
+        table = gncCloneTaxTable (table, book);
+    }
+    return table;
+}
+
+
+void
+gncTaxTableDestroy (GncTaxTable *table)
+{
+    if (!table) return;
+    qof_instance_set_destroying(table, TRUE);
+    qof_instance_set_dirty (&table->inst);
+    gncTaxTableCommitEdit (table);
+}
+
+static void
+gncTaxTableFree (GncTaxTable *table)
+{
+    GList *list;
+    GncTaxTable *child;
+
+    if (!table) return;
+
+    qof_event_gen (&table->inst, QOF_EVENT_DESTROY, NULL);
+    CACHE_REMOVE (table->name);
+    remObj (table);
+
+    /* destroy the list of entries */
+    for (list = table->entries; list; list = list->next)
+        gncTaxTableEntryDestroy (list->data);
+    g_list_free (table->entries);
+
+    if (!qof_instance_get_destroying(table))
+        PERR("free a taxtable without do_free set!");
+
+    /* disconnect from parent */
+    if (table->parent)
+        gncTaxTableRemoveChild(table->parent, table);
+
+    /* disconnect from the children */
+    for (list = table->children; list; list = list->next)
+    {
+        child = list->data;
+        gncTaxTableSetParent(child, NULL);
+    }
+    g_list_free(table->children);
+
+    /* qof_instance_release (&table->inst); */
+    g_object_unref (table);
+}
+
+/* =============================================================== */
+
+GncTaxTableEntry * gncTaxTableEntryCreate (void)
+{
+    GncTaxTableEntry *entry;
+    entry = g_new0 (GncTaxTableEntry, 1);
+    entry->amount = gnc_numeric_zero ();
+    return entry;
+}
+
+void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
+{
+    if (!entry) return;
+    g_free (entry);
+}
+
+/** Makes a clone. The account is from the appriate book.
+ *  Note that the table is left blank (for performance reasons
+ *  we set it above, when cloning the table).
+ */
+static GncTaxTableEntry *
+CloneTaxEntry (const GncTaxTableEntry*from, QofBook *book)
+{
+    QofInstance *acc;
+    GncTaxTableEntry *entry;
+    entry = g_new0 (GncTaxTableEntry, 1);
+
+    entry->type = from->type;
+    entry->amount = from->amount;
+
+    acc = qof_instance_lookup_twin (QOF_INSTANCE(from->account), book);
+    entry->account = (Account *) acc;
+    return entry;
+}
+
+/* =============================================================== */
+/* Set Functions */
+
+void gncTaxTableSetName (GncTaxTable *table, const char *name)
+{
+    if (!table || !name) return;
+    SET_STR (table, table->name, name);
+    mark_table (table);
+    maybe_resort_list (table);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent)
+{
+    if (!table) return;
+    gncTaxTableBeginEdit (table);
+    if (table->parent)
+        gncTaxTableRemoveChild(table->parent, table);
+    table->parent = parent;
+    if (parent)
+        gncTaxTableAddChild(parent, table);
+    table->refcount = 0;
+    gncTaxTableMakeInvisible (table);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child)
+{
+    if (!table) return;
+    gncTaxTableBeginEdit (table);
+    table->child = child;
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableIncRef (GncTaxTable *table)
+{
+    if (!table) return;
+    if (table->parent || table->invisible) return;        /* children dont need refcounts */
+    gncTaxTableBeginEdit (table);
+    table->refcount++;
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableDecRef (GncTaxTable *table)
+{
+    if (!table) return;
+    if (table->parent || table->invisible) return;        /* children dont need refcounts */
+    gncTaxTableBeginEdit (table);
+    table->refcount--;
+    g_return_if_fail (table->refcount >= 0);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount)
+{
+    if (!table) return;
+    table->refcount = refcount;
+}
+
+void gncTaxTableMakeInvisible (GncTaxTable *table)
+{
+    struct _book_info *bi;
+    if (!table) return;
+    gncTaxTableBeginEdit (table);
+    table->invisible = TRUE;
+    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
+    bi->tables = g_list_remove (bi->tables, table);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account)
+{
+    if (!entry || !account) return;
+    if (entry->account == account) return;
+    entry->account = account;
+    if (entry->table)
+    {
+        mark_table (entry->table);
+        mod_table (entry->table);
+    }
+}
+
+void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type)
+{
+    if (!entry) return;
+    if (entry->type == type) return;
+    entry->type = type;
+    if (entry->table)
+    {
+        mark_table (entry->table);
+        mod_table (entry->table);
+    }
+}
+
+void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount)
+{
+    if (!entry) return;
+    if (gnc_numeric_eq (entry->amount, amount)) return;
+    entry->amount = amount;
+    if (entry->table)
+    {
+        mark_table (entry->table);
+        mod_table (entry->table);
+    }
+}
+
+void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry)
+{
+    if (!table || !entry) return;
+    if (entry->table == table) return; /* already mine */
+
+    gncTaxTableBeginEdit (table);
+    if (entry->table)
+        gncTaxTableRemoveEntry (entry->table, entry);
+
+    entry->table = table;
+    table->entries = g_list_insert_sorted (table->entries, entry,
+                                           (GCompareFunc)gncTaxTableEntryCompare);
+    mark_table (table);
+    mod_table (table);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry)
+{
+    if (!table || !entry) return;
+    gncTaxTableBeginEdit (table);
+    entry->table = NULL;
+    table->entries = g_list_remove (table->entries, entry);
+    mark_table (table);
+    mod_table (table);
+    gncTaxTableCommitEdit (table);
+}
+
+void gncTaxTableChanged (GncTaxTable *table)
+{
+    if (!table) return;
+    gncTaxTableBeginEdit (table);
+    table->child = NULL;
+    gncTaxTableCommitEdit (table);
+}
+
+/* =============================================================== */
+
+void gncTaxTableBeginEdit (GncTaxTable *table)
+{
+    qof_begin_edit(&table->inst);
+}
+
+static void gncTaxTableOnError (QofInstance *inst, QofBackendError errcode)
+{
+    PERR("TaxTable QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncTaxTableOnDone (QofInstance *inst) {}
+
+static void table_free (QofInstance *inst)
+{
+    GncTaxTable *table = (GncTaxTable *) inst;
+    gncTaxTableFree (table);
+}
+
+void gncTaxTableCommitEdit (GncTaxTable *table)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(table))) return;
+    qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,
+                           gncTaxTableOnDone, table_free);
+}
+
+
+/* =============================================================== */
+/* Get Functions */
+
+GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name)
+{
+    GList *list = gncTaxTableGetTables (book);
+
+    for ( ; list; list = list->next)
+    {
+        GncTaxTable *table = list->data;
+        if (!safe_strcmp (table->name, name))
+            return list->data;
+    }
+    return NULL;
+}
+
+GList * gncTaxTableGetTables (QofBook *book)
+{
+    struct _book_info *bi;
+    if (!book) return NULL;
+
+    bi = qof_book_get_data (book, _GNC_MOD_NAME);
+    return bi->tables;
+}
+
+const char *gncTaxTableGetName (const GncTaxTable *table)
+{
+    if (!table) return NULL;
+    return table->name;
+}
+
+static GncTaxTableEntry *gncTaxTableEntryCopy (const GncTaxTableEntry *entry)
+{
+    GncTaxTableEntry *e;
+    if (!entry) return NULL;
+
+    e = gncTaxTableEntryCreate ();
+    gncTaxTableEntrySetAccount (e, entry->account);
+    gncTaxTableEntrySetType (e, entry->type);
+    gncTaxTableEntrySetAmount (e, entry->amount);
+
+    return e;
+}
+
+static GncTaxTable *gncTaxTableCopy (const GncTaxTable *table)
+{
+    GncTaxTable *t;
+    GList *list;
+
+    if (!table) return NULL;
+    t = gncTaxTableCreate (qof_instance_get_book(table));
+    gncTaxTableSetName (t, table->name);
+    for (list = table->entries; list; list = list->next)
+    {
+        GncTaxTableEntry *entry, *e;
+        entry = list->data;
+        e = gncTaxTableEntryCopy (entry);
+        gncTaxTableAddEntry (t, e);
+    }
+    return t;
+}
+
+GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new)
+{
+    GncTaxTable *child = NULL;
+
+    if (!table) return NULL;
+    if (table->child) return table->child;
+    if (table->parent || table->invisible) return table;
+    if (make_new)
+    {
+        child = gncTaxTableCopy (table);
+        gncTaxTableSetChild (table, child);
+        gncTaxTableSetParent (child, table);
+    }
+    return child;
+}
+
+GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table)
+{
+    if (!table) return NULL;
+    return table->parent;
+}
+
+GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table)
+{
+    if (!table) return NULL;
+    return table->entries;
+}
+
+gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
+{
+    if (!table) return 0;
+    return table->refcount;
+}
+
+Timespec gncTaxTableLastModified (const GncTaxTable *table)
+{
+    Timespec ts = { 0 , 0 };
+    if (!table) return ts;
+    return table->modtime;
+}
+
+gboolean gncTaxTableGetInvisible (const GncTaxTable *table)
+{
+    if (!table) return FALSE;
+    return table->invisible;
+}
+
+Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry)
+{
+    if (!entry) return NULL;
+    return entry->account;
+}
+
+GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry)
+{
+    if (!entry) return 0;
+    return entry->type;
+}
+
+gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry)
+{
+    if (!entry) return gnc_numeric_zero();
+    return entry->amount;
+}
+
+GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry )
+{
+    if (!entry) return NULL;
+    return entry->table;
+}
+
+int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
+{
+    char *name_a, *name_b;
+    int retval;
+
+    if (!a && !b) return 0;
+    if (!a) return -1;
+    if (!b) return 1;
+
+    name_a = gnc_account_get_full_name (a->account);
+    name_b = gnc_account_get_full_name (b->account);
+    retval = safe_strcmp(name_a, name_b);
+    g_free(name_a);
+    g_free(name_b);
+
+    if (retval)
+        return retval;
+
+    return gnc_numeric_compare (a->amount, b->amount);
+}
+
+int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b)
+{
+    if (!a && !b) return 0;
+    if (!a) return -1;
+    if (!b) return 1;
+    return safe_strcmp (a->name, b->name);
+}
+
+gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    if (!xaccAccountEqual(a->account, b->account, TRUE))
+    {
+        PWARN("accounts differ");
+        return FALSE;
+    }
+
+    if (a->type != b->type)
+    {
+        PWARN("types differ");
+        return FALSE;
+    }
+
+    if (!gnc_numeric_equal(a->amount, b->amount))
+    {
+        PWARN("amounts differ");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL || b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
+    g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("Names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+
+    if (a->invisible != b->invisible)
+    {
+        PWARN("invisible flags differ");
+        return FALSE;
+    }
+
+    if ((a->entries != NULL) != (b->entries != NULL))
+    {
+        PWARN("only one has entries");
+        return FALSE;
+    }
+
+    if (a->entries != NULL && b->entries != NULL)
+    {
+        GncTaxTableEntryList* a_node;
+        GncTaxTableEntryList* b_node;
+
+        for (a_node = a->entries, b_node = b->entries;
+                a_node != NULL && b_node != NULL;
+                a_node = a_node->next, b_node = b_node->next)
+        {
+            if (!gncTaxTableEntryEqual((GncTaxTableEntry*)a_node->data,
+                                       (GncTaxTableEntry*)b_node->data))
+            {
+                PWARN("entries differ");
+                return FALSE;
+            }
+        }
+
+        if (a_node != NULL || b_node != NULL)
+        {
+            PWARN("Unequal number of entries");
+            return FALSE;
+        }
+    }
+
+#if 0
+    /* See src/doc/business.txt for an explanation of the following */
+    /* Code that handles this is *identical* to that in gncBillTerm */
+    gint64          refcount;
+    GncTaxTable *   parent;       /* if non-null, we are an immutable child */
+    GncTaxTable *   child;        /* if non-null, we have not changed */
+    GList *         children;     /* list of children for disconnection */
+#endif
+
+    return TRUE;
+}
+
+/*
+ * This will add value to the account-value for acc, creating a new
+ * list object if necessary
+ */
+GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value)
+{
+    GList *li;
+    GncAccountValue *res = NULL;
+
+    g_return_val_if_fail (acc, list);
+    g_return_val_if_fail (gnc_numeric_check (value) == GNC_ERROR_OK, list);
+
+    /* Try to find the account in the list */
+    for (li = list; li; li = li->next)
+    {
+        res = li->data;
+        if (res->account == acc)
+        {
+            res->value = gnc_numeric_add (res->value, value, GNC_DENOM_AUTO,
+                                          GNC_DENOM_LCD);
+            return list;
+        }
+    }
+    /* Nope, didn't find it. */
+
+    res = g_new0 (GncAccountValue, 1);
+    res->account = acc;
+    res->value = value;
+    return g_list_prepend (list, res);
+}
+
+/* Merge l2 into l1.  l2 is not touched. */
+GList *gncAccountValueAddList (GList *l1, GList *l2)
+{
+    GList *li;
+
+    for (li = l2; li; li = li->next )
+    {
+        GncAccountValue *val = li->data;
+        l1 = gncAccountValueAdd (l1, val->account, val->value);
+    }
+
+    return l1;
+}
+
+/* return the total for this list */
+gnc_numeric gncAccountValueTotal (GList *list)
+{
+    gnc_numeric total = gnc_numeric_zero ();
+
+    for ( ; list ; list = list->next)
+    {
+        GncAccountValue *val = list->data;
+        total = gnc_numeric_add (total, val->value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+    }
+    return total;
+}
+
+/* Destroy a list of accountvalues */
+void gncAccountValueDestroy (GList *list)
+{
+    GList *node;
+    for ( node = list; node ; node = node->next)
+        g_free (node->data);
+
+    g_list_free (list);
+}
+
+/* Package-Private functions */
+
+static void _gncTaxTableCreate (QofBook *book)
+{
+    struct _book_info *bi;
+
+    if (!book) return;
+
+    bi = g_new0 (struct _book_info, 1);
+    qof_book_set_data (book, _GNC_MOD_NAME, bi);
+}
+
+static void _gncTaxTableDestroy (QofBook *book)
+{
+    struct _book_info *bi;
+
+    if (!book) return;
+
+    bi = qof_book_get_data (book, _GNC_MOD_NAME);
+
+    g_list_free (bi->tables);
+    g_free (bi);
+}
+
+static QofObject gncTaxTableDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Tax Table",
+    DI(.create            = ) (gpointer)gncTaxTableCreate,
+    DI(.book_begin        = ) _gncTaxTableCreate,
+    DI(.book_end          = ) _gncTaxTableDestroy,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) NULL,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncTaxTableRegister (void)
+{
+    static QofParam params[] =
+    {
+        { GNC_TT_NAME, 		QOF_TYPE_STRING, 	(QofAccessFunc)gncTaxTableGetName, 		(QofSetterFunc)gncTaxTableSetName },
+        { GNC_TT_REFCOUNT, 	QOF_TYPE_INT64, 	(QofAccessFunc)gncTaxTableGetRefcount, 	(QofSetterFunc)gncTaxTableSetRefcount },
+        { QOF_PARAM_BOOK, 	QOF_ID_BOOK, 		(QofAccessFunc)qof_instance_get_book, 	NULL },
+        { QOF_PARAM_GUID, 	QOF_TYPE_GUID, 		(QofAccessFunc)qof_instance_get_guid, 	NULL },
+        { NULL },
+    };
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params);
+
+    return qof_object_register (&gncTaxTableDesc);
+}
+
+/* need a QOF tax table entry object */
+//gncTaxTableEntrySetType_q int32
+//gint gncTaxTableEntryGetType_q (GncTaxTableEntry *entry);

Copied: gnucash/trunk/src/engine/gncTaxTable.h (from rev 19328, gnucash/trunk/src/business/business-core/gncTaxTable.h)
===================================================================
--- gnucash/trunk/src/engine/gncTaxTable.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncTaxTable.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,209 @@
+/********************************************************************\
+ * gncTaxTable.h -- the Gnucash Tax Table interface                 *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup TaxTable
+    @{ */
+/** @file gncTaxTable.h
+    @brief Tax Table programming interface
+    @author Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_TAXTABLE_H_
+#define GNC_TAXTABLE_H_
+
+/** @struct GncTaxTable
+
+modtime is the internal date of the last modtime\n
+See src/doc/business.txt for an explanation of the following\n
+Code that handles refcount, parent, child, invisible and children
+is *identical* to that in ::GncBillTerm
+
+ at param	QofInstance     inst;
+ at param 	char *          name;
+ at param 	GncTaxTableEntryList*  entries;
+ at param 	Timespec        modtime;
+ at param 	gint64          refcount;
+ at param 	GncTaxTable *   parent; if non-null, we are an immutable child
+ at param 	GncTaxTable *   child;  if non-null, we have not changed
+ at param 	gboolean        invisible;
+ at param 	GList *         children; list of children for disconnection
+*/
+typedef struct _gncTaxTable GncTaxTable;
+typedef struct _gncTaxTableClass GncTaxTableClass;
+
+/** @struct GncTaxTableEntry
+
+ at param	GncTaxTable *   table;
+ at param  Account *       account;
+ at param	GncAmountType   type;
+ at param	gnc_numeric     amount;
+};
+
+*/
+typedef struct _gncTaxTableEntry GncTaxTableEntry;
+
+typedef struct _gncAccountValue GncAccountValue;
+
+#include "Account.h"
+#include "qof.h"
+#ifdef GNUCASH_MAJOR_VERSION
+#include "gncBusiness.h"
+#endif
+
+#define GNC_ID_TAXTABLE       "gncTaxTable"
+
+/* --- type macros --- */
+#define GNC_TYPE_TAXTABLE            (gnc_taxtable_get_type ())
+#define GNC_TAXTABLE(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))
+#define GNC_TAXTABLE_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))
+#define GNC_IS_TAXTABLE(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))
+#define GNC_IS_TAXTABLE_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))
+#define GNC_TAXTABLE_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
+GType gnc_taxtable_get_type(void);
+
+/**
+ * How to interpret the amount.
+ * You can interpret it as a VALUE or a PERCENT.
+ */
+typedef enum
+{
+    GNC_AMT_TYPE_VALUE = 1, 	/**< tax is a number */
+    GNC_AMT_TYPE_PERCENT		/**< tax is a percentage */
+} GncAmountType;
+
+/** How to interpret the TaxIncluded */
+typedef enum
+{
+    GNC_TAXINCLUDED_YES = 1,  /**< tax is included */
+    GNC_TAXINCLUDED_NO,		/**< tax is not included */
+    GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
+} GncTaxIncluded;
+
+const char * gncAmountTypeToString (GncAmountType type);
+gboolean gncAmountStringToType (const char *str, GncAmountType *type);
+
+const char * gncTaxIncludedTypeToString (GncTaxIncluded type);
+gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type);
+
+/** @name Create/Destroy Functions
+ @{ */
+GncTaxTable * gncTaxTableCreate (QofBook *book);
+void gncTaxTableDestroy (GncTaxTable *table);
+GncTaxTableEntry * gncTaxTableEntryCreate (void);
+void gncTaxTableEntryDestroy (GncTaxTableEntry *entry);
+/** @} */
+/** \name Set Functions
+@{
+*/
+void gncTaxTableSetName (GncTaxTable *table, const char *name);
+void gncTaxTableIncRef (GncTaxTable *table);
+void gncTaxTableDecRef (GncTaxTable *table);
+
+void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account);
+void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type);
+void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount);
+/** @} */
+void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry);
+void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry);
+
+void gncTaxTableChanged (GncTaxTable *table);
+void gncTaxTableBeginEdit (GncTaxTable *table);
+void gncTaxTableCommitEdit (GncTaxTable *table);
+gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b);
+
+/** @name Get Functions
+ @{ */
+
+/** Return a pointer to the instance gncTaxTable that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncTaxTable * gncTaxTableLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
+}
+
+GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
+
+GList * gncTaxTableGetTables (QofBook *book);
+
+const char *gncTaxTableGetName (const GncTaxTable *table);
+GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
+GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
+#define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
+typedef GList GncTaxTableEntryList;
+GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
+gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
+Timespec gncTaxTableLastModified (const GncTaxTable *table);
+
+Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
+GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
+gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
+/** @} */
+
+int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
+int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
+gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
+
+/************************************************/
+
+struct _gncAccountValue
+{
+    Account *	account;
+    gnc_numeric	value;
+};
+
+/**
+ * This will add value to the account-value for acc, creating a new
+ * list object if necessary
+ */
+GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value);
+
+/** Merge l2 into l1.  l2 is not touched. */
+GList *gncAccountValueAddList (GList *l1, GList *l2);
+
+/** return the total for this list */
+gnc_numeric gncAccountValueTotal (GList *list);
+
+/** Destroy a list of accountvalues */
+void gncAccountValueDestroy (GList *list);
+
+/** QOF parameter definitions */
+#define GNC_TT_NAME "tax table name"
+#define GNC_TT_REFCOUNT "reference count"
+
+/** @deprecated routine */
+#define gncTaxTableGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
+#define gncTaxTableRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
+#define gncTaxTableLookupDirect(G,B) gncTaxTableLookup((B), &(G))
+
+#endif /* GNC_TAXTABLE_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncTaxTableP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncTaxTableP.h)
===================================================================
--- gnucash/trunk/src/engine/gncTaxTableP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncTaxTableP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,70 @@
+/********************************************************************\
+ * gncTaxTableP.h -- the Gnucash Tax Table private interface        *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2002 Derek Atkins
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_TAXTABLEP_H_
+#define GNC_TAXTABLEP_H_
+
+#include "gncTaxTable.h"
+
+gboolean gncTaxTableRegister (void);
+
+void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent);
+void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child);
+void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount);
+void gncTaxTableMakeInvisible (GncTaxTable *table);
+
+gboolean gncTaxTableGetInvisible (const GncTaxTable *table);
+
+/** The gncCloneTaxTable() routine makes a copy of the indicated
+ *  tax table, placing it in the indicated book.  It copies
+ *  the tax table name and list of entries.
+ *  It also copies (as needed) both parents and children, so that
+ *  the parent-child relationship is correctly mirrored in the
+ *  clone.
+ * XXX the refcount is mis-handled. This needs fixin....
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book);
+
+/** The gncTaxTableObtainTwin() will find the 'twin' of the
+ *  indicated tax table in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneTaxTable()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncTaxTable * gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book);
+
+GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry );
+
+#define gncTaxTableSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
+
+#endif /* GNC_TAXTABLEP_H_ */

Copied: gnucash/trunk/src/engine/gncVendor.c (from rev 19328, gnucash/trunk/src/business/business-core/gncVendor.c)
===================================================================
--- gnucash/trunk/src/engine/gncVendor.c	                        (rev 0)
+++ gnucash/trunk/src/engine/gncVendor.c	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,843 @@
+/********************************************************************\
+ * gncVendor.c -- the Core Vendor Interface                         *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001, 2002 Derek Atkins
+ * Copyright (C) 2003 <linas at linas.org>
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <string.h>
+
+#include "gnc-commodity.h"
+#include "gncAddressP.h"
+#include "gncBillTermP.h"
+#include "gncInvoice.h"
+#include "gncJobP.h"
+#include "gncTaxTableP.h"
+#include "gncVendor.h"
+#include "gncVendorP.h"
+
+static gint gs_address_event_handler_id = 0;
+static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                                      gpointer user_data, gpointer event_data);
+
+struct _gncVendor
+{
+    QofInstance     inst;
+
+    char *          id;
+    char *          name;
+    char *          notes;
+    GncBillTerm *   terms;
+    GncAddress *    addr;
+    gnc_commodity * currency;
+    GncTaxTable*    taxtable;
+    gboolean        taxtable_override;
+    GncTaxIncluded  taxincluded;
+    gboolean        active;
+    GList *         jobs;
+};
+
+struct _gncVendorClass
+{
+    QofInstanceClass parent_class;
+};
+
+static QofLogModule log_module = GNC_MOD_BUSINESS;
+
+#define _GNC_MOD_NAME        GNC_ID_VENDOR
+
+/* ============================================================ */
+/* Misc inline funcs */
+
+G_INLINE_FUNC void mark_vendor (GncVendor *vendor);
+void mark_vendor (GncVendor *vendor)
+{
+    qof_instance_set_dirty(&vendor->inst);
+    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+/* ============================================================== */
+
+enum
+{
+    PROP_0,
+    PROP_NAME
+};
+
+/* GObject Initialization */
+G_DEFINE_TYPE(GncVendor, gnc_vendor, QOF_TYPE_INSTANCE);
+
+static void
+gnc_vendor_init(GncVendor* vendor)
+{
+}
+
+static void
+gnc_vendor_dispose(GObject *vendorp)
+{
+    G_OBJECT_CLASS(gnc_vendor_parent_class)->dispose(vendorp);
+}
+
+static void
+gnc_vendor_finalize(GObject* vendorp)
+{
+    G_OBJECT_CLASS(gnc_vendor_parent_class)->finalize(vendorp);
+}
+
+static void
+gnc_vendor_get_property (GObject         *object,
+                         guint            prop_id,
+                         GValue          *value,
+                         GParamSpec      *pspec)
+{
+    GncVendor *vendor;
+
+    g_return_if_fail(GNC_IS_VENDOR(object));
+
+    vendor = GNC_VENDOR(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        g_value_set_string(value, vendor->name);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_vendor_set_property (GObject         *object,
+                         guint            prop_id,
+                         const GValue          *value,
+                         GParamSpec      *pspec)
+{
+    GncVendor *vendor;
+
+    g_return_if_fail(GNC_IS_VENDOR(object));
+
+    vendor = GNC_VENDOR(object);
+    switch (prop_id)
+    {
+    case PROP_NAME:
+        gncVendorSetName(vendor, g_value_get_string(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+/** Return displayable name */
+static gchar*
+impl_get_display_name(const QofInstance* inst)
+{
+    GncVendor* v;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
+
+    v = GNC_VENDOR(inst);
+    return g_strdup_printf("Vendor %s", v->name);
+}
+
+/** Does this object refer to a specific object */
+static gboolean
+impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
+{
+    GncVendor* v;
+
+    g_return_val_if_fail(inst != NULL, FALSE);
+    g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
+
+    v = GNC_VENDOR(inst);
+
+    if (GNC_IS_BILLTERM(ref))
+    {
+        return (v->terms == GNC_BILLTERM(ref));
+    }
+    else if (GNC_IS_TAXTABLE(ref))
+    {
+        return (v->taxtable == GNC_TAXTABLE(ref));
+    }
+
+    return FALSE;
+}
+
+/** Returns a list of my type of object which refers to an object.  For example, when called as
+        qof_instance_get_typed_referring_object_list(taxtable, account);
+    it will return the list of taxtables which refer to a specific account.  The result should be the
+    same regardless of which taxtable object is used.  The list must be freed by the caller but the
+    objects on the list must not.
+ */
+static GList*
+impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
+{
+    if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
+    {
+        return NULL;
+    }
+
+    return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
+}
+
+static void
+gnc_vendor_class_init (GncVendorClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
+
+    gobject_class->dispose = gnc_vendor_dispose;
+    gobject_class->finalize = gnc_vendor_finalize;
+    gobject_class->set_property = gnc_vendor_set_property;
+    gobject_class->get_property = gnc_vendor_get_property;
+
+    qof_class->get_display_name = NULL;
+    qof_class->refers_to_object = impl_refers_to_object;
+    qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
+
+    g_object_class_install_property
+    (gobject_class,
+     PROP_NAME,
+     g_param_spec_string ("name",
+                          "Vendor Name",
+                          "The vendor name is an arbitrary string "
+                          "assigned by the user to provide the vendor name.",
+                          NULL,
+                          G_PARAM_READWRITE));
+}
+
+/* Create/Destroy Functions */
+GncVendor *gncVendorCreate (QofBook *book)
+{
+    GncVendor *vendor;
+
+    if (!book) return NULL;
+
+    vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
+    qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
+
+    vendor->id = CACHE_INSERT ("");
+    vendor->name = CACHE_INSERT ("");
+    vendor->notes = CACHE_INSERT ("");
+    vendor->addr = gncAddressCreate (book, &vendor->inst);
+    vendor->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
+    vendor->active = TRUE;
+    vendor->jobs = NULL;
+
+    if (gs_address_event_handler_id == 0)
+    {
+        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+    }
+
+    qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
+
+    return vendor;
+}
+
+void gncVendorDestroy (GncVendor *vendor)
+{
+    if (!vendor) return;
+    qof_instance_set_destroying(vendor, TRUE);
+    gncVendorCommitEdit (vendor);
+}
+
+static void gncVendorFree (GncVendor *vendor)
+{
+    if (!vendor) return;
+
+    qof_event_gen (&vendor->inst, QOF_EVENT_DESTROY, NULL);
+
+    CACHE_REMOVE (vendor->id);
+    CACHE_REMOVE (vendor->name);
+    CACHE_REMOVE (vendor->notes);
+    gncAddressBeginEdit (vendor->addr);
+    gncAddressDestroy (vendor->addr);
+    g_list_free (vendor->jobs);
+
+    if (vendor->terms)
+        gncBillTermDecRef (vendor->terms);
+    if (vendor->taxtable)
+        gncTaxTableDecRef (vendor->taxtable);
+
+    /* qof_instance_release (&vendor->inst); */
+    g_object_unref (vendor);
+}
+
+/** Create a copy of a vendor, placing the copy into a new book. */
+GncVendor *
+gncCloneVendor (GncVendor *from, QofBook *book)
+{
+    GList *node;
+    GncVendor *vendor;
+
+    if (!book) return NULL;
+
+    vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
+    qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
+    qof_instance_gemini (&vendor->inst, &from->inst);
+
+    vendor->id = CACHE_INSERT (from->id);
+    vendor->name = CACHE_INSERT (from->name);
+    vendor->notes = CACHE_INSERT (from->notes);
+    vendor->addr = gncCloneAddress (from->addr, &vendor->inst, book);
+    vendor->taxincluded = from->taxincluded;
+    vendor->taxtable_override = from->taxtable_override;
+    vendor->active = from->active;
+
+    vendor->terms = gncBillTermObtainTwin (from->terms, book);
+    gncBillTermIncRef (vendor->terms);
+
+    vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
+
+    vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
+    gncTaxTableIncRef (vendor->taxtable);
+
+    vendor->jobs = NULL;
+    for (node = g_list_last(from->jobs); node; node = node->prev)
+    {
+        GncJob *job = node->data;
+        job = gncJobObtainTwin (job, book);
+        vendor->jobs = g_list_prepend(vendor->jobs, job);
+    }
+
+    qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
+
+    return vendor;
+}
+
+GncVendor *
+gncVendorObtainTwin (GncVendor *from, QofBook *book)
+{
+    GncVendor *vendor;
+    if (!book) return NULL;
+
+    vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+    if (!vendor)
+    {
+        vendor = gncCloneVendor (from, book);
+    }
+
+    return vendor;
+}
+
+/* ============================================================== */
+/* Set Functions */
+
+#define SET_STR(obj, member, str) { \
+        char * tmp; \
+        \
+        if (!safe_strcmp (member, str)) return; \
+        gncVendorBeginEdit (obj); \
+        tmp = CACHE_INSERT (str); \
+        CACHE_REMOVE (member); \
+        member = tmp; \
+        }
+
+void gncVendorSetID (GncVendor *vendor, const char *id)
+{
+    if (!vendor) return;
+    if (!id) return;
+    SET_STR(vendor, vendor->id, id);
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetName (GncVendor *vendor, const char *name)
+{
+    if (!vendor) return;
+    if (!name) return;
+    SET_STR(vendor, vendor->name, name);
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetNotes (GncVendor *vendor, const char *notes)
+{
+    if (!vendor) return;
+    if (!notes) return;
+    SET_STR(vendor, vendor->notes, notes);
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
+{
+    if (!vendor) return;
+    if (vendor->terms == terms) return;
+
+    gncVendorBeginEdit (vendor);
+    if (vendor->terms)
+        gncBillTermDecRef (vendor->terms);
+    vendor->terms = terms;
+    if (vendor->terms)
+        gncBillTermIncRef (vendor->terms);
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl)
+{
+    if (!vendor) return;
+    if (taxincl == vendor->taxincluded) return;
+    gncVendorBeginEdit (vendor);
+    vendor->taxincluded = taxincl;
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency)
+{
+    if (!vendor || !currency) return;
+    if (vendor->currency &&
+            gnc_commodity_equal (vendor->currency, currency))
+        return;
+    gncVendorBeginEdit (vendor);
+    vendor->currency = currency;
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetActive (GncVendor *vendor, gboolean active)
+{
+    if (!vendor) return;
+    if (active == vendor->active) return;
+    gncVendorBeginEdit (vendor);
+    vendor->active = active;
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override)
+{
+    if (!vendor) return;
+    if (vendor->taxtable_override == override) return;
+    gncVendorBeginEdit (vendor);
+    vendor->taxtable_override = override;
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table)
+{
+    if (!vendor) return;
+    if (vendor->taxtable == table) return;
+    gncVendorBeginEdit (vendor);
+    if (vendor->taxtable)
+        gncTaxTableDecRef (vendor->taxtable);
+    if (table)
+        gncTaxTableIncRef (table);
+    vendor->taxtable = table;
+    mark_vendor (vendor);
+    gncVendorCommitEdit (vendor);
+}
+
+static void
+qofVendorSetAddr (GncVendor *vendor, QofInstance *addr_ent)
+{
+    GncAddress *addr;
+
+    if (!vendor || !addr_ent)
+    {
+        return;
+    }
+    addr = (GncAddress*)addr_ent;
+    if (addr == vendor->addr)
+    {
+        return;
+    }
+    if (vendor->addr != NULL)
+    {
+        gncAddressBeginEdit(vendor->addr);
+        gncAddressDestroy(vendor->addr);
+    }
+    gncVendorBeginEdit(vendor);
+    vendor->addr = addr;
+    gncVendorCommitEdit(vendor);
+}
+
+static void
+qofVendorSetTaxIncluded(GncVendor *vendor, const char* type_string)
+{
+    GncTaxIncluded inc;
+
+    if (!gncTaxIncludedStringToType(type_string, &inc))
+    {
+        return;
+    }
+    gncVendorBeginEdit(vendor);
+    vendor->taxincluded = inc;
+    gncVendorCommitEdit(vendor);
+}
+
+/* ============================================================== */
+/* Get Functions */
+
+const char * gncVendorGetID (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->id;
+}
+
+const char * gncVendorGetName (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->name;
+}
+
+GncAddress * gncVendorGetAddr (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->addr;
+}
+
+const char * gncVendorGetNotes (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->notes;
+}
+
+GncBillTerm * gncVendorGetTerms (const GncVendor *vendor)
+{
+    if (!vendor) return 0;
+    return vendor->terms;
+}
+
+GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor)
+{
+    if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
+    return vendor->taxincluded;
+}
+
+gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->currency;
+}
+
+gboolean gncVendorGetActive (const GncVendor *vendor)
+{
+    if (!vendor) return FALSE;
+    return vendor->active;
+}
+
+gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor)
+{
+    if (!vendor) return FALSE;
+    return vendor->taxtable_override;
+}
+
+GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor)
+{
+    if (!vendor) return NULL;
+    return vendor->taxtable;
+}
+
+static const char*
+qofVendorGetTaxIncluded(const GncVendor *vendor)
+{
+    return gncTaxIncludedTypeToString(vendor->taxincluded);
+}
+
+/* Note that JobList changes do not affect the "dirtiness" of the vendor */
+void gncVendorAddJob (GncVendor *vendor, GncJob *job)
+{
+    if (!vendor) return;
+    if (!job) return;
+
+    if (g_list_index(vendor->jobs, job) == -1)
+        vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
+                                             (GCompareFunc)gncJobCompare);
+
+    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
+{
+    GList *node;
+
+    if (!vendor) return;
+    if (!job) return;
+
+    node = g_list_find (vendor->jobs, job);
+    if (!node)
+    {
+        /*    PERR ("split not in account"); */
+    }
+    else
+    {
+        vendor->jobs = g_list_remove_link (vendor->jobs, node);
+        g_list_free_1 (node);
+    }
+
+    qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
+}
+
+void gncVendorBeginEdit (GncVendor *vendor)
+{
+    qof_begin_edit(&vendor->inst);
+}
+
+static void gncVendorOnError (QofInstance *vendor, QofBackendError errcode)
+{
+    PERR("Vendor QofBackend Failure: %d", errcode);
+    gnc_engine_signal_commit_error( errcode );
+}
+
+static void gncVendorOnDone (QofInstance *inst)
+{
+    GncVendor *vendor = (GncVendor *) inst;
+    gncAddressClearDirty (vendor->addr);
+}
+
+static void vendor_free (QofInstance *inst)
+{
+    GncVendor *vendor = (GncVendor *) inst;
+    gncVendorFree (vendor);
+}
+
+void gncVendorCommitEdit (GncVendor *vendor)
+{
+    if (!qof_commit_edit (QOF_INSTANCE(vendor))) return;
+    qof_commit_edit_part2 (&vendor->inst, gncVendorOnError,
+                           gncVendorOnDone, vendor_free);
+}
+
+/* ============================================================== */
+/* Other functions */
+
+int gncVendorCompare (const GncVendor *a, const GncVendor *b)
+{
+    if (!a && !b) return 0;
+    if (!a && b) return 1;
+    if (a && !b) return -1;
+
+    return(strcmp(a->name, b->name));
+}
+
+gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
+{
+    if (a == NULL && b == NULL) return TRUE;
+    if (a == NULL ||  b == NULL) return FALSE;
+
+    g_return_val_if_fail(GNC_IS_VENDOR(a), FALSE);
+    g_return_val_if_fail(GNC_IS_VENDOR(b), FALSE);
+
+    if (safe_strcmp(a->id, b->id) != 0)
+    {
+        PWARN("IDs differ: %s vs %s", a->id, b->id);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->name, b->name) != 0)
+    {
+        PWARN("Names differ: %s vs %s", a->name, b->name);
+        return FALSE;
+    }
+
+    if (safe_strcmp(a->notes, b->notes) != 0)
+    {
+        PWARN("Notes differ");
+        return FALSE;
+    }
+
+    if (!gncBillTermEqual(a->terms, b->terms))
+    {
+        PWARN("BillTerms differ");
+        return FALSE;
+    }
+
+    if (!gncAddressEqual(a->addr, b->addr))
+    {
+        PWARN("Addresses differ");
+        return FALSE;
+    }
+
+    if (!gnc_commodity_equal(a->currency, b->currency))
+    {
+        PWARN("Currencies differ");
+        return FALSE;
+    }
+
+    if (!gncTaxTableEqual(a->taxtable, b->taxtable))
+    {
+        PWARN("Tax tables differ");
+        return FALSE;
+    }
+
+    if (a->taxtable_override != b->taxtable_override)
+    {
+        PWARN("Tax table override flags differ");
+        return FALSE;
+    }
+
+    if (a->taxincluded != b->taxincluded)
+    {
+        PWARN("Tax included flags differ");
+        return FALSE;
+    }
+
+    if (a->active != b->active)
+    {
+        PWARN("Active flags differ");
+        return FALSE;
+    }
+
+//    GList *         jobs;
+    return TRUE;
+}
+
+GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
+{
+    if (!vendor) return NULL;
+
+    if (show_all)
+    {
+        return (g_list_copy (vendor->jobs));
+    }
+    else
+    {
+        GList *list = NULL, *iterator;
+        for (iterator = vendor->jobs; iterator; iterator = iterator->next)
+        {
+            GncJob *j = iterator->data;
+            if (gncJobGetActive (j))
+                list = g_list_append (list, j);
+        }
+        return list;
+    }
+}
+
+gboolean gncVendorIsDirty (const GncVendor *vendor)
+{
+    if (!vendor) return FALSE;
+    return (qof_instance_get_dirty_flag(vendor)
+            || gncAddressIsDirty (vendor->addr));
+}
+
+/**
+ * Listens for MODIFY events from addresses.   If the address belongs to a vendor,
+ * mark the vendor as dirty.
+ *
+ * @param entity Entity for the event
+ * @param event_type Event type
+ * @param user_data User data registered with the handler
+ * @param event_data Event data passed with the event.
+ */
+static void
+listen_for_address_events(QofInstance *entity, QofEventId event_type,
+                          gpointer user_data, gpointer event_data)
+{
+    GncVendor* v;
+
+    if ((event_type & QOF_EVENT_MODIFY) == 0)
+    {
+        return;
+    }
+    if (!GNC_IS_ADDRESS(entity))
+    {
+        return;
+    }
+    if (!GNC_IS_VENDOR(event_data))
+    {
+        return;
+    }
+    v = GNC_VENDOR(event_data);
+    gncVendorBeginEdit(v);
+    mark_vendor(v);
+    gncVendorCommitEdit(v);
+}
+/* ============================================================== */
+/* Package-Private functions */
+
+static const char * _gncVendorPrintable (gpointer item)
+{
+    GncVendor *v = item;
+    if (!item) return NULL;
+    return v->name;
+}
+
+static QofObject gncVendorDesc =
+{
+    DI(.interface_version = ) QOF_OBJECT_VERSION,
+    DI(.e_type            = ) _GNC_MOD_NAME,
+    DI(.type_label        = ) "Vendor",
+    DI(.create            = ) (gpointer)gncVendorCreate,
+    DI(.book_begin        = ) NULL,
+    DI(.book_end          = ) NULL,
+    DI(.is_dirty          = ) qof_collection_is_dirty,
+    DI(.mark_clean        = ) qof_collection_mark_clean,
+    DI(.foreach           = ) qof_collection_foreach,
+    DI(.printable         = ) _gncVendorPrintable,
+    DI(.version_cmp       = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+};
+
+gboolean gncVendorRegister (void)
+{
+    static QofParam params[] =
+    {
+        { VENDOR_ID, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetID, (QofSetterFunc)gncVendorSetID },
+        { VENDOR_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetName, (QofSetterFunc)gncVendorSetName },
+        { VENDOR_ADDR,    GNC_ID_ADDRESS, (QofAccessFunc)gncVendorGetAddr, (QofSetterFunc)qofVendorSetAddr },
+        { VENDOR_NOTES,   QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetNotes, (QofSetterFunc)gncVendorSetNotes },
+        { VENDOR_TERMS,   GNC_ID_BILLTERM, (QofAccessFunc)gncVendorGetTerms, (QofSetterFunc)gncVendorSetTerms },
+        {
+            VENDOR_TAX_OVERRIDE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetTaxTableOverride,
+            (QofSetterFunc)gncVendorSetTaxTableOverride
+        },
+        {
+            VENDOR_TAX_TABLE, GNC_ID_TAXTABLE, (QofAccessFunc)gncVendorGetTaxTable,
+            (QofSetterFunc)gncVendorSetTaxTable
+        },
+        {
+            VENDOR_TAX_INC, QOF_TYPE_STRING, (QofAccessFunc)qofVendorGetTaxIncluded,
+            (QofSetterFunc)qofVendorSetTaxIncluded
+        },
+        { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+        { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+        { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetActive, NULL },
+        { NULL },
+    };
+
+    if (!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_VENDOR, INVOICE_OWNER))
+    {
+        return FALSE;
+    }
+    if (!qof_choice_add_class(GNC_ID_JOB, GNC_ID_VENDOR, JOB_OWNER))
+    {
+        return FALSE;
+    }
+
+    qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params);
+
+    return qof_object_register (&gncVendorDesc);
+}
+
+gint64 gncVendorNextID (QofBook *book)
+{
+    return qof_book_get_counter (book, _GNC_MOD_NAME);
+}

Copied: gnucash/trunk/src/engine/gncVendor.h (from rev 19328, gnucash/trunk/src/business/business-core/gncVendor.h)
===================================================================
--- gnucash/trunk/src/engine/gncVendor.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncVendor.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,139 @@
+/********************************************************************\
+ * gncVendor.h -- the Core Vendor Interface                         *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+/** @addtogroup Business
+    @{ */
+/** @addtogroup Vendor
+    @{ */
+/** @file gncVendor.h
+    @brief  Vendor Interface
+    @author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
+*/
+
+#ifndef GNC_VENDOR_H_
+#define GNC_VENDOR_H_
+
+typedef struct _gncVendor GncVendor;
+typedef struct _gncVendorClass GncVendorClass;
+
+#include "gncAddress.h"
+#include "gncBillTerm.h"
+#include "gncTaxTable.h"
+#include "gncJob.h"
+
+#define GNC_ID_VENDOR       "gncVendor"
+
+/* --- type macros --- */
+#define GNC_TYPE_VENDOR            (gnc_vendor_get_type ())
+#define GNC_VENDOR(o)              \
+     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_VENDOR, GncVendor))
+#define GNC_VENDOR_CLASS(k)        \
+     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_VENDOR, GncVendorClass))
+#define GNC_IS_VENDOR(o)           \
+     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_VENDOR))
+#define GNC_IS_VENDOR_CLASS(k)     \
+     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_VENDOR))
+#define GNC_VENDOR_GET_CLASS(o)    \
+     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_VENDOR, GncVendorClass))
+GType gnc_vendor_get_type(void);
+
+/* Create/Destroy Functions */
+
+GncVendor *gncVendorCreate (QofBook *book);
+void gncVendorDestroy (GncVendor *vendor);
+
+/** @name Set Functions
+ @{
+*/
+
+void gncVendorSetID (GncVendor *vendor, const char *id);
+void gncVendorSetName (GncVendor *vendor, const char *name);
+void gncVendorSetNotes (GncVendor *vendor, const char *notes);
+void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms);
+void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl);
+void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency);
+void gncVendorSetActive (GncVendor *vendor, gboolean active);
+void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override);
+void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table);
+
+/** @} */
+
+void gncVendorAddJob (GncVendor *vendor, GncJob *job);
+void gncVendorRemoveJob (GncVendor *vendor, GncJob *job);
+
+void gncVendorBeginEdit (GncVendor *vendor);
+void gncVendorCommitEdit (GncVendor *vendor);
+
+/** @name Get Functions
+@{
+*/
+
+const char * gncVendorGetID (const GncVendor *vendor);
+const char * gncVendorGetName (const GncVendor *vendor);
+GncAddress * gncVendorGetAddr (const GncVendor *vendor);
+const char * gncVendorGetNotes (const GncVendor *vendor);
+GncBillTerm * gncVendorGetTerms (const GncVendor *vendor);
+GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor);
+gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor);
+gboolean gncVendorGetActive (const GncVendor *vendor);
+
+gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor);
+GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor);
+
+/** @} */
+/** XXX should be renamed to RetJobList to be consistent with
+ * other usage, since caller must free the copied list
+ */
+GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all);
+gboolean gncVendorIsDirty (const GncVendor *vendor);
+int gncVendorCompare (const GncVendor *a, const GncVendor *b);
+gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b);
+
+/** Return a pointer to the instance gncVendor that is identified
+ *  by the guid, and is residing in the book. Returns NULL if the
+ *  instance can't be found.
+ *  Equivalent function prototype is
+ *  GncVendor * gncVendorLookup (QofBook *book, const GncGUID *guid);
+ */
+static inline GncVendor * gncVendorLookup (const QofBook *book, const GncGUID *guid)
+{
+    QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_VENDOR, GncVendor);
+}
+
+#define VENDOR_ID	"id"
+#define VENDOR_NAME	"name"
+#define VENDOR_ADDR	"addr"
+#define VENDOR_NOTES "vendor_notes"
+#define VENDOR_TERMS "vendor_terms"
+#define VENDOR_TAX_INC "vendor_tax_included"
+#define VENDOR_ACTIVE "vendor_is_active"
+#define VENDOR_TAX_OVERRIDE "override_tax_table"
+#define VENDOR_TAX_TABLE "vendor_tax_table"
+
+/** deprecated functions */
+#define gncVendorGetBook(X) qof_instance_get_book (QOF_INSTANCE(X))
+#define gncVendorGetGUID(X) qof_instance_get_guid (QOF_INSTANCE(X))
+#define gncVendorRetGUID(X) (X ? *(qof_instance_get_guid (QOF_INSTANCE(X))) : *(guid_null()))
+#define gncVendorLookupDirect(G,B) gncVendorLookup((B),&(G))
+
+#endif /* GNC_VENDOR_H_ */
+/** @} */
+/** @} */

Copied: gnucash/trunk/src/engine/gncVendorP.h (from rev 19328, gnucash/trunk/src/business/business-core/gncVendorP.h)
===================================================================
--- gnucash/trunk/src/engine/gncVendorP.h	                        (rev 0)
+++ gnucash/trunk/src/engine/gncVendorP.h	2010-07-03 21:53:22 UTC (rev 19329)
@@ -0,0 +1,58 @@
+/********************************************************************\
+ * gncVendorP.h -- the Core Vendor Interface                        *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+/*
+ * Copyright (C) 2001 Derek Atkins
+ * Author: Derek Atkins <warlord at MIT.EDU>
+ */
+
+#ifndef GNC_VENDORP_H_
+#define GNC_VENDORP_H_
+
+#include "gncVendor.h"
+
+gboolean gncVendorRegister (void);
+gint64 gncVendorNextID (QofBook *book);
+
+/** The gncCloneVendor() routine makes a copy of the indicated
+ *  vendor, placing it in the indicated book.  It copies
+ *  the name, notes, address, etc.
+ *  It then adds a pair of 'gemini' kvp pointers so that each copy
+ *  can be found from the other.
+ */
+
+GncVendor * gncCloneVendor (GncVendor *from, QofBook *);
+
+/** The gncVendorObtainTwin() will find the 'twin' of the
+ *  indicated vendor in the indicated book.  If the twin doesn't
+ *  yet exist in the book, it will be created (by calling
+ *  gncCloneVendor()) and placed into the book.
+ *
+ * We called this routine 'Obtain' instead of "Get" to distinguish
+ * it from the other Get routines, which work in fundamentally
+ * different ways.
+ */
+GncVendor * gncVendorObtainTwin (GncVendor *from, QofBook *book);
+#define gncVendorSetGUID(V,G) qof_instance_set_guid(QOF_INSTANCE(V),(G))
+
+
+#endif /* GNC_VENDORP_H_ */

Modified: gnucash/trunk/src/gnc/main.cpp
===================================================================
--- gnucash/trunk/src/gnc/main.cpp	2010-07-03 21:53:08 UTC (rev 19328)
+++ gnucash/trunk/src/gnc/main.cpp	2010-07-03 21:53:22 UTC (rev 19329)
@@ -48,7 +48,7 @@
 #include "swig-runtime.h"
 
 #include "backend/xml/gnc-backend-xml.h"
-#include "business/business-core/gncBusiness.h"
+#include "engine/gncBusiness.h"
 #include "business/business-core/xml/gncmod-business-backend-xml.h"
 #ifdef WITH_SQL
 #  include "backend/dbi/gnc-backend-dbi.h"



More information about the gnucash-changes mailing list