r18789 - gnucash/trunk/src/business - Re-indentation of source code, next batch: src/business/*
Christian Stimming
cstim at code.gnucash.org
Tue Mar 2 16:41:07 EST 2010
Author: cstim
Date: 2010-03-02 16:41:05 -0500 (Tue, 02 Mar 2010)
New Revision: 18789
Trac: http://svn.gnucash.org/trac/changeset/18789
Modified:
gnucash/trunk/src/business/business-core/gncAddress.c
gnucash/trunk/src/business/business-core/gncAddress.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/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/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/gncVendor.c
gnucash/trunk/src/business/business-core/gncVendor.h
gnucash/trunk/src/business/business-core/gncVendorP.h
gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c
gnucash/trunk/src/business/business-core/test/test-address.c
gnucash/trunk/src/business/business-core/test/test-business.c
gnucash/trunk/src/business/business-core/test/test-customer.c
gnucash/trunk/src/business/business-core/test/test-employee.c
gnucash/trunk/src/business/business-core/test/test-job.c
gnucash/trunk/src/business/business-core/test/test-load-module.c
gnucash/trunk/src/business/business-core/test/test-vendor.c
gnucash/trunk/src/business/business-core/xml/gnc-address-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-bill-term-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-customer-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-employee-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-entry-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-invoice-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-job-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-order-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.h
gnucash/trunk/src/business/business-core/xml/gnc-tax-table-xml-v2.c
gnucash/trunk/src/business/business-core/xml/gnc-vendor-xml-v2.c
gnucash/trunk/src/business/business-core/xml/xml-helpers.h
gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
gnucash/trunk/src/business/business-gnome/business-gnome-utils.h
gnucash/trunk/src/business/business-gnome/business-options-gnome.c
gnucash/trunk/src/business/business-gnome/business-urls.c
gnucash/trunk/src/business/business-gnome/dialog-billterms.c
gnucash/trunk/src/business/business-gnome/dialog-choose-owner.c
gnucash/trunk/src/business/business-gnome/dialog-customer.c
gnucash/trunk/src/business/business-gnome/dialog-date-close.c
gnucash/trunk/src/business/business-gnome/dialog-date-close.h
gnucash/trunk/src/business/business-gnome/dialog-employee.c
gnucash/trunk/src/business/business-gnome/dialog-invoice.c
gnucash/trunk/src/business/business-gnome/dialog-invoice.h
gnucash/trunk/src/business/business-gnome/dialog-job.c
gnucash/trunk/src/business/business-gnome/dialog-job.h
gnucash/trunk/src/business/business-gnome/dialog-order.c
gnucash/trunk/src/business/business-gnome/dialog-order.h
gnucash/trunk/src/business/business-gnome/dialog-payment.c
gnucash/trunk/src/business/business-gnome/dialog-payment.h
gnucash/trunk/src/business/business-gnome/dialog-vendor.c
gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
gnucash/trunk/src/business/business-gnome/gnc-plugin-business.h
gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.h
gnucash/trunk/src/business/business-gnome/search-owner.c
gnucash/trunk/src/business/business-gnome/search-owner.h
gnucash/trunk/src/business/business-ledger/gncEntryLedger.c
gnucash/trunk/src/business/business-ledger/gncEntryLedger.h
gnucash/trunk/src/business/business-ledger/gncEntryLedgerControl.c
gnucash/trunk/src/business/business-ledger/gncEntryLedgerDisplay.c
gnucash/trunk/src/business/business-ledger/gncEntryLedgerLayout.c
gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
gnucash/trunk/src/business/business-ledger/gncEntryLedgerModel.c
gnucash/trunk/src/business/business-ledger/gncEntryLedgerP.h
gnucash/trunk/src/business/business-utils/business-options.c
gnucash/trunk/src/business/business-utils/business-options.h
gnucash/trunk/src/business/dialog-tax-table/dialog-tax-table.c
Log:
Re-indentation of source code, next batch: src/business/*
This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.24 using the following options:
astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix=none
Modified: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncAddress.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -33,26 +33,26 @@
#include "gncAddressP.h"
#include "gncCustomerP.h"
-struct _gncAddress
+struct _gncAddress
{
- QofInstance inst;
+ QofInstance inst;
- QofBook * book;
- QofInstance * parent;
- gboolean dirty;
- char * name;
- char * addr1;
- char * addr2;
- char * addr3;
- char * addr4;
- char * phone;
- char * fax;
- char * email;
+ 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;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -62,15 +62,16 @@
G_INLINE_FUNC void mark_address (GncAddress *address);
void mark_address (GncAddress *address)
{
- address->dirty = TRUE;
+ address->dirty = TRUE;
- qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
- qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (QOF_INSTANCE(address), QOF_EVENT_MODIFY, address->parent);
+ qof_event_gen (address->parent, QOF_EVENT_MODIFY, NULL);
}
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -95,43 +96,45 @@
static void
gnc_address_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ g_value_set_string(value, address->name);
+ 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)
+ 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;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ gncAddressSetName(address, g_value_get_string(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
@@ -139,124 +142,133 @@
gnc_address_class_init (GncAddressClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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));
}
/* Create/Destroy functions */
-GncAddress *
+GncAddress *
gncAddressCreate (QofBook *book, QofInstance *prnt)
{
- GncAddress *addr;
+ GncAddress *addr;
- if (!book) return NULL;
+ 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 = 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 ("");
+ 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;
+ return addr;
}
-static GncAddress *
+static GncAddress *
qofAddressCreate (QofBook *book)
{
- /* The address will get set later by another function */
- return gncAddressCreate(book, NULL);
+ /* 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; }
+ if (!addr || !ent)
+ {
+ return;
+ }
+ if (addr->parent == NULL)
+ {
+ addr->parent = ent;
+ }
}
static QofInstance*
qofAddressGetOwner(const GncAddress *addr)
{
- if(!addr) { return NULL; }
- return addr->parent;
+ if (!addr)
+ {
+ return NULL;
+ }
+ return addr->parent;
}
-GncAddress *
+GncAddress *
gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book)
{
- GncAddress *addr;
+ GncAddress *addr;
- if (!book) return NULL;
+ 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 = 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);
+ 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;
+ return addr;
}
-void
+void
gncAddressDestroy (GncAddress *addr)
{
- if (!addr) return;
- qof_instance_set_destroying(addr, TRUE);
- gncAddressCommitEdit (addr);
+ if (!addr) return;
+ qof_instance_set_destroying(addr, TRUE);
+ gncAddressCommitEdit (addr);
}
static void
gncAddressFree (GncAddress *addr)
{
- if (!addr) return;
+ if (!addr) return;
- qof_event_gen (&addr->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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);
+ /* qof_instance_release (&addr->inst); */
+ g_object_unref (addr);
}
@@ -275,209 +287,213 @@
void gncAddressSetName (GncAddress *addr, const char *name)
{
- if (!addr) return;
- if (!name) return;
- SET_STR(addr, addr->name, name);
- mark_address (addr);
- gncAddressCommitEdit (addr);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ qof_begin_edit (&addr->inst);
}
static void gncAddressOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("Address QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ 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;
+ if (!addr) return NULL;
+ return addr->name;
}
const char * gncAddressGetAddr1 (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->addr1;
+ if (!addr) return NULL;
+ return addr->addr1;
}
const char * gncAddressGetAddr2 (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->addr2;
+ if (!addr) return NULL;
+ return addr->addr2;
}
const char * gncAddressGetAddr3 (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->addr3;
+ if (!addr) return NULL;
+ return addr->addr3;
}
const char * gncAddressGetAddr4 (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->addr4;
+ if (!addr) return NULL;
+ return addr->addr4;
}
const char * gncAddressGetPhone (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->phone;
+ if (!addr) return NULL;
+ return addr->phone;
}
const char * gncAddressGetFax (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->fax;
+ if (!addr) return NULL;
+ return addr->fax;
}
const char * gncAddressGetEmail (const GncAddress *addr)
{
- if (!addr) return NULL;
- return addr->email;
+ if (!addr) return NULL;
+ return addr->email;
}
gboolean gncAddressIsDirty (const GncAddress *addr)
{
- if (!addr) return FALSE;
- return addr->dirty;
+ if (!addr) return FALSE;
+ return addr->dirty;
}
void gncAddressClearDirty (GncAddress *addr)
{
- if (!addr) return;
- addr->dirty = FALSE;
+ 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;
+ if (!a && !b) return 0;
+ if (!a && b) return 1;
+ if (a && !b) return -1;
- return safe_strcmp (a->name, b->name);
+ return safe_strcmp (a->name, b->name);
}
static QofObject GncAddressDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = GNC_ID_ADDRESS,
- .type_label = "Address",
- .create = (gpointer)qofAddressCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = NULL,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = GNC_ID_ADDRESS,
+ .type_label = "Address",
+ .create = (gpointer)qofAddressCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = NULL,
+ .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
gboolean gncAddressRegister (void)
{
- static QofParam params[] = {
+ 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 },
- };
+ { 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; }
+ 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);
+ return qof_object_register(&GncAddressDesc);
}
Modified: gnucash/trunk/src/business/business-core/gncAddress.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncAddress.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -93,7 +93,7 @@
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_ADDRESS, GncAddressClass))
GType gnc_address_get_type(void);
-/** @name Create/Destroy functions
+/** @name Create/Destroy functions
@{ */
GncAddress *gncAddressCreate (QofBook *book, QofInstance *parent);
void gncAddressDestroy (GncAddress *addr);
@@ -102,7 +102,7 @@
/** @} */
-/** @name Set functions
+/** @name Set functions
@{ */
void gncAddressSetName (GncAddress *addr, const char *name);
@@ -116,7 +116,7 @@
void gncAddressClearDirty (GncAddress *address);
/** @} */
-/** @name Get Functions
+/** @name Get Functions
@{ */
const char * gncAddressGetName (const GncAddress *addr);
@@ -131,10 +131,10 @@
gboolean gncAddressIsDirty (const GncAddress *addr);
-/** \brief compare two addresses
+/** \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.
+\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);
Modified: gnucash/trunk/src/business/business-core/gncBillTerm.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -33,37 +33,37 @@
#include "gnc-engine.h"
#include "gncBillTermP.h"
-struct _gncBillTerm
+struct _gncBillTerm
{
- QofInstance inst;
+ 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;
+ /* '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 */
+ /* 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;
+ QofInstanceClass parent_class;
};
-struct _book_info
+struct _book_info
{
- GList * terms; /* visible terms */
+ GList * terms; /* visible terms */
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -89,53 +89,54 @@
static inline void
mark_term (GncBillTerm *term)
{
- qof_instance_set_dirty(&term->inst);
- qof_event_gen (&term->inst, QOF_EVENT_MODIFY, NULL);
+ 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;
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ if (qof_instance_get_destroying(table)) return;
+ table->children = g_list_remove(table->children, child);
}
/* ============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -160,43 +161,45 @@
static void
gnc_billterm_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -204,142 +207,143 @@
gnc_billterm_class_init (GncBillTermClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ 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;
+ 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);
+ 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;
+ GncBillTerm *child;
+ GList *list;
- if (!term) return;
+ if (!term) return;
- qof_event_gen (&term->inst, QOF_EVENT_DESTROY, NULL);
- CACHE_REMOVE (term->name);
- CACHE_REMOVE (term->desc);
- remObj (term);
+ 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!");
+ 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 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);
+ /* 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);
+ /* qof_instance_release(&term->inst); */
+ g_object_unref (term);
}
GncBillTerm *
gncCloneBillTerm (GncBillTerm *from, QofBook *book)
{
- GList *node;
- GncBillTerm *term;
+ GList *node;
+ GncBillTerm *term;
- if (!book || !from) return NULL;
+ 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 = 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->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;
+ 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);
- }
+ /* 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;
+ 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;
+ GncBillTerm *term;
+ if (!from) return NULL;
- term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!term)
- {
- term = gncCloneBillTerm (from, book);
- }
- return term;
+ term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!term)
+ {
+ term = gncCloneBillTerm (from, book);
+ }
+ return term;
}
/* ============================================================== */
@@ -347,30 +351,30 @@
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);
+ 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);
+ 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);
+ 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. */
@@ -379,50 +383,50 @@
static
void qofBillTermSetType (GncBillTerm *term, const char *type_label)
{
- GncBillTermType type;
+ GncBillTermType type;
- type = GncBillTermTypefromString(type_label);
- gncBillTermSetType(term, 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);
+ 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);
+ 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);
+ 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);
+ 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
@@ -432,133 +436,135 @@
*/
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);
+ 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);
+ 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);
+ 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);
+ 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;
+ if (!term) return;
+ term->refcount = refcount;
}
void gncBillTermMakeInvisible (GncBillTerm *term)
{
- if (!term) return;
- gncBillTermBeginEdit (term);
- term->invisible = TRUE;
- remObj (term);
- gncBillTermCommitEdit (term);
+ if (!term) return;
+ gncBillTermBeginEdit (term);
+ term->invisible = TRUE;
+ remObj (term);
+ gncBillTermCommitEdit (term);
}
void gncBillTermChanged (GncBillTerm *term)
{
- if (!term) return;
- term->child = NULL;
+ if (!term) return;
+ term->child = NULL;
}
void gncBillTermBeginEdit (GncBillTerm *term)
{
- qof_begin_edit(&term->inst);
+ qof_begin_edit(&term->inst);
}
static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("BillTerm QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ 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);
+ GList *list = gncBillTermGetTerms (book);
- for ( ; list; list = list->next) {
- GncBillTerm *term = list->data;
- if (!safe_strcmp (term->name, name))
- return list->data;
- }
- return NULL;
+ 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;
+ struct _book_info *bi;
+ if (!book) return NULL;
- bi = qof_book_get_data (book, _GNC_MOD_NAME);
- return bi->terms;
+ 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;
+ if (!term) return NULL;
+ return term->name;
}
const char *gncBillTermGetDescription (const GncBillTerm *term)
{
- if (!term) return NULL;
- return term->desc;
+ if (!term) return NULL;
+ return term->desc;
}
GncBillTermType gncBillTermGetType (const GncBillTerm *term)
{
- if (!term) return 0;
- return term->type;
+ if (!term) return 0;
+ return term->type;
}
/** \brief Convert bill term types to text. */
@@ -567,108 +573,112 @@
static
const char* qofBillTermGetType (const GncBillTerm *term)
{
- if (!term) { return NULL; }
- return GncBillTermTypeasString(term->type);
+ if (!term)
+ {
+ return NULL;
+ }
+ return GncBillTermTypeasString(term->type);
}
gint gncBillTermGetDueDays (const GncBillTerm *term)
{
- if (!term) return 0;
- return term->due_days;
+ if (!term) return 0;
+ return term->due_days;
}
gint gncBillTermGetDiscountDays (const GncBillTerm *term)
{
- if (!term) return 0;
- return term->disc_days;
+ if (!term) return 0;
+ return term->disc_days;
}
gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term)
{
- if (!term) return gnc_numeric_zero ();
- return term->discount;
+ if (!term) return gnc_numeric_zero ();
+ return term->discount;
}
gint gncBillTermGetCutoff (const GncBillTerm *term)
{
- if (!term) return 0;
- return term->cutoff;
+ if (!term) return 0;
+ return term->cutoff;
}
static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
{
- GncBillTerm *t;
+ GncBillTerm *t;
- if (!term) return NULL;
- t = gncBillTermCreate (qof_instance_get_book(term));
+ if (!term) return NULL;
+ t = gncBillTermCreate (qof_instance_get_book(term));
- gncBillTermBeginEdit(t);
+ gncBillTermBeginEdit(t);
- gncBillTermSetName (t, term->name);
- gncBillTermSetDescription (t, term->desc);
+ 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;
+ 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);
+ gncBillTermCommitEdit(t);
- return t;
+ return t;
}
GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new)
{
- GncBillTerm *child = NULL;
+ 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;
+ 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;
+ if (!term) return NULL;
+ return term->parent;
}
gint64 gncBillTermGetRefcount (const GncBillTerm *term)
{
- if (!term) return 0;
- return term->refcount;
+ if (!term) return 0;
+ return term->refcount;
}
gboolean gncBillTermGetInvisible (const GncBillTerm *term)
{
- if (!term) return FALSE;
- return term->invisible;
+ if (!term) return FALSE;
+ return term->invisible;
}
int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b)
{
- int ret;
+ int ret;
- if (!a && !b) return 0;
- if (!a) return -1;
- if (!b) return 1;
+ if (!a && !b) return 0;
+ if (!a) return -1;
+ if (!b) return 1;
- ret = safe_strcmp (a->name, b->name);
- if (ret) return ret;
+ ret = safe_strcmp (a->name, b->name);
+ if (ret) return ret;
- return safe_strcmp (a->desc, b->desc);
+ return safe_strcmp (a->desc, b->desc);
}
gboolean gncBillTermIsDirty (const GncBillTerm *term)
{
- if (!term) return FALSE;
- return qof_instance_get_dirty_flag(term);
+ if (!term) return FALSE;
+ return qof_instance_get_dirty_flag(term);
}
/********************************************************/
@@ -684,31 +694,35 @@
compute_monthyear (const GncBillTerm *term, Timespec post_date,
int *month, int *year)
{
- int iday, imonth, iyear;
- int cutoff = term->cutoff;
+ int iday, imonth, iyear;
+ int cutoff = term->cutoff;
- g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
+ g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
- gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
+ gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
- if (cutoff <= 0)
- cutoff += gnc_timespec_last_mday (post_date);
+ 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 (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 (imonth > 12)
+ {
+ iyear++;
+ imonth -= 12;
+ }
- if (month) *month = imonth;
- if (year) *year = iyear;
+ if (month) *month = imonth;
+ if (year) *year = iyear;
}
/* XXX explain this, the logic is totally opaque to me. */
@@ -716,98 +730,100 @@
static Timespec
compute_time (const GncBillTerm *term, Timespec post_date, int days)
{
- Timespec res = post_date;
- int day, month, year;
+ 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;
+ 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;
+ Timespec res = post_date;
+ if (!term) return res;
- return compute_time (term, post_date, term->due_days);
+ 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;
+ Timespec res = post_date;
+ if (!term) return res;
- return compute_time (term, post_date, term->disc_days);
+ return compute_time (term, post_date, term->disc_days);
}
/* Package-Private functions */
static void _gncBillTermCreate (QofBook *book)
{
- struct _book_info *bi;
+ struct _book_info *bi;
- if (!book) return;
+ if (!book) return;
- bi = g_new0 (struct _book_info, 1);
- qof_book_set_data (book, _GNC_MOD_NAME, bi);
+ 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;
+ struct _book_info *bi;
- if (!book) return;
+ if (!book) return;
- bi = qof_book_get_data (book, _GNC_MOD_NAME);
+ bi = qof_book_get_data (book, _GNC_MOD_NAME);
- g_list_free (bi->terms);
- g_free (bi);
+ g_list_free (bi->terms);
+ g_free (bi);
}
-static QofObject gncBillTermDesc =
+static QofObject gncBillTermDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Billing Term",
- .create = (gpointer)gncBillTermCreate,
- .book_begin = _gncBillTermCreate,
- .book_end = _gncBillTermDestroy,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = NULL,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Billing Term",
+ .create = (gpointer)gncBillTermCreate,
+ .book_begin = _gncBillTermCreate,
+ .book_end = _gncBillTermDestroy,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = NULL,
+ .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 },
- };
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);
- return qof_object_register (&gncBillTermDesc);
+ return qof_object_register (&gncBillTermDesc);
}
Modified: gnucash/trunk/src/business/business-core/gncBillTerm.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTerm.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBillTerm.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -79,13 +79,14 @@
DEFINE_ENUM(GncBillTermType, ENUM_TERMS_TYPE)
#else
-typedef enum {
- GNC_TERM_TYPE_DAYS = 1,
- GNC_TERM_TYPE_PROXIMO,
+typedef enum
+{
+ GNC_TERM_TYPE_DAYS = 1,
+ GNC_TERM_TYPE_PROXIMO,
} GncBillTermType;
#endif
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncBillTerm * gncBillTermCreate (QofBook *book);
void gncBillTermDestroy (GncBillTerm *term);
@@ -97,7 +98,7 @@
void gncBillTermCommitEdit (GncBillTerm *term);
/** @} */
-/** @name Set Functions
+/** @name Set Functions
@{
*/
void gncBillTermSetName (GncBillTerm *term, const char *name);
@@ -110,10 +111,10 @@
/** @} */
-/** @name Get Functions
+/** @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
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncBillTermP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBillTermP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBillTermP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -42,9 +42,9 @@
/** 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.
+ * 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
+ * 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
@@ -59,7 +59,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncBusGuile.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusGuile.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBusGuile.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -32,61 +32,61 @@
static swig_type_info *
get_acct_type ()
{
- static swig_type_info * account_type = NULL;
+ static swig_type_info * account_type = NULL;
- if (!account_type)
- account_type = SWIG_TypeQuery("_p_Account");
+ if (!account_type)
+ account_type = SWIG_TypeQuery("_p_Account");
- return account_type;
+ return account_type;
}
int gnc_account_value_pointer_p (SCM arg)
{
- swig_type_info * account_type = get_acct_type();
+ 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)));
+ 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;
+ 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;
+ /* Get the account */
+ val = SCM_CAR (valuearg);
+ if (!SWIG_IsPointerOfType (val, account_type))
+ return NULL;
- acc = SWIG_MustGetPtr(val, account_type, 1, 0);
+ acc = SWIG_MustGetPtr(val, account_type, 1, 0);
- /* Get the value */
- val = SCM_CDR (valuearg);
- value = gnc_scm_to_numeric (val);
+ /* 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;
+ /* 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;
+ swig_type_info * account_type = get_acct_type();
+ gnc_commodity * com;
+ gnc_numeric val;
- if (!av) return SCM_BOOL_F;
+ if (!av) return SCM_BOOL_F;
- com = xaccAccountGetCommodity (av->account);
- val = gnc_numeric_convert (av->value, gnc_commodity_get_fraction (com),
- GNC_RND_ROUND);
+ 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));
+ return scm_cons (SWIG_NewPointerObj(av->account, account_type, 0),
+ gnc_numeric_to_scm (val));
}
Modified: gnucash/trunk/src/business/business-core/gncBusPeriod.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusPeriod.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBusPeriod.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,29 +1,29 @@
/*
XXX TODO:
--- contemplate a per-collection (per type) edit/commmit-edit,
+-- contemplate a per-collection (per type) edit/commmit-edit,
clone, dirty, etc. functions some more ...
--- turn clone into a generic object callback, so that
+-- 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
+-- 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
+ 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
+ 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.
@@ -33,7 +33,7 @@
-- finish clone of invoice, entry,
--- jobs in the vendor job list that are no longer active should
+-- 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 ??
@@ -51,22 +51,22 @@
void
gncCustomerCopyAll (QofBook *dest_book, QofBook *src_book)
{
-
+
}
-static void
+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);
+ 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);
+ qof_object_foreach (GNC_BILLTERM_MODULE_NAME,
+ src_book, bill_term_copy_helper, dest_book);
}
@@ -74,8 +74,8 @@
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);
+ /* 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);
}
Modified: gnucash/trunk/src/business/business-core/gncBusiness.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusiness.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBusiness.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,5 +1,5 @@
/*
- * gncBusiness.c -- Business helper functions
+ * gncBusiness.c -- Business helper functions
* Copyright (C) 2002 Derek Atkins
* Author: Derek Atkins <warlord at MIT.EDU>
*
@@ -28,7 +28,7 @@
#include "gncBusiness.h"
#include "gncBusinessP.h"
-/* This file is currently unused;
- * its contents have been moved to qofid.[ch]
+/* This file is currently unused;
+ * its contents have been moved to qofid.[ch]
*/
// void gncBusinessInitialize (int argc, char **argv) {}
Modified: gnucash/trunk/src/business/business-core/gncBusiness.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncBusiness.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncBusiness.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -20,7 +20,7 @@
/** @addtogroup Engine
@{ */
/** @addtogroup Business
- The Business Engine provides a set of structures for
+ The Business Engine provides a set of structures for
that provide small-business accounting features.
@{ */
Modified: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -47,34 +47,34 @@
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);
+ gpointer user_data, gpointer event_data);
struct _gncCustomer
{
- QofInstance inst;
+ 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 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;
+ /* The following fields are unique to 'customer' */
+ gnc_numeric credit;
+ gnc_numeric discount;
+ GncAddress * shipaddr;
};
struct _gncCustomerClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -87,15 +87,16 @@
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);
+ qof_instance_set_dirty(&customer->inst);
+ qof_event_gen (&customer->inst, QOF_EVENT_MODIFY, NULL);
}
/* ============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -120,43 +121,45 @@
static void
gnc_customer_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -164,144 +167,146 @@
gnc_customer_class_init (GncCustomerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ GncCustomer *cust;
- if (!book) return NULL;
+ if (!book) return NULL;
- cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
- qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
+ 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->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);
+ 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);
- }
+ 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);
+ qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
- return cust;
+ 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;
+ GList *node;
+ GncCustomer *cust;
- cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
+ 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);
+ 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->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);
+ 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 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);
+ /* 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);
- }
+ 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);
+ qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);
- return cust;
+ return cust;
}
void gncCustomerDestroy (GncCustomer *cust)
{
- if (!cust) return;
- qof_instance_set_destroying(cust, TRUE);
- qof_instance_set_dirty (&cust->inst);
- gncCustomerCommitEdit (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;
+ if (!cust) return;
- qof_event_gen (&cust->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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);
- }
+ if (cust->terms)
+ gncBillTermDecRef (cust->terms);
+ if (cust->taxtable)
+ {
+ gncTaxTableDecRef (cust->taxtable);
+ }
- /* qof_instance_release (&cust->inst); */
- g_object_unref (cust);
+ /* qof_instance_release (&cust->inst); */
+ g_object_unref (cust);
}
GncCustomer *
gncCustomerObtainTwin (GncCustomer *from, QofBook *book)
{
- GncCustomer *cust;
- if (!from) return NULL;
+ GncCustomer *cust;
+ if (!from) return NULL;
- cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!cust)
- {
- cust = gncCloneCustomer (from, book);
- }
- return cust;
+ cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!cust)
+ {
+ cust = gncCloneCustomer (from, book);
+ }
+ return cust;
}
/* ============================================================== */
@@ -319,180 +324,183 @@
void gncCustomerSetID (GncCustomer *cust, const char *id)
{
- if (!cust) return;
- if (!id) return;
- SET_STR(cust, cust->id, id);
- mark_customer (cust);
- gncCustomerCommitEdit (cust);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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 (!cust) return;
+ if (!job) return;
- if (g_list_index(cust->jobs, job) == -1)
- cust->jobs = g_list_insert_sorted (cust->jobs, job,
- (GCompareFunc)gncJobCompare);
+ 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);
+ qof_event_gen (&cust->inst, QOF_EVENT_MODIFY, NULL);
}
void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
{
- GList *node;
+ GList *node;
- if (!cust) return;
- if (!job) return;
+ 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);
+ 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);
+ qof_begin_edit (&cust->inst);
}
static void gncCustomerOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("Customer QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ GncCustomer *cust = (GncCustomer *) inst;
+ gncAddressClearDirty (cust->addr);
+ gncAddressClearDirty (cust->shipaddr);
}
static void cust_free (QofInstance *inst)
{
- GncCustomer *cust = (GncCustomer *) inst;
- gncCustomerFree (cust);
+ 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);
+ if (!qof_commit_edit (QOF_INSTANCE(cust))) return;
+ qof_commit_edit_part2 (&cust->inst, gncCustomerOnError,
+ gncCustomerOnDone, cust_free);
}
/* ============================================================== */
@@ -500,150 +508,168 @@
const char * gncCustomerGetID (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->id;
+ if (!cust) return NULL;
+ return cust->id;
}
const char * gncCustomerGetName (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->name;
+ if (!cust) return NULL;
+ return cust->name;
}
GncAddress * gncCustomerGetAddr (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->addr;
+ if (!cust) return NULL;
+ return cust->addr;
}
static void
qofCustomerSetAddr (GncCustomer *cust, QofInstance *addr_ent)
{
- GncAddress *addr;
+ 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);
+ 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;
+ 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);
+ 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;
+ if (!cust) return NULL;
+ return cust->shipaddr;
}
const char * gncCustomerGetNotes (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->notes;
+ if (!cust) return NULL;
+ return cust->notes;
}
GncBillTerm * gncCustomerGetTerms (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->terms;
+ if (!cust) return NULL;
+ return cust->terms;
}
GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *cust)
{
- if (!cust) return GNC_TAXINCLUDED_USEGLOBAL;
- return cust->taxincluded;
+ if (!cust) return GNC_TAXINCLUDED_USEGLOBAL;
+ return cust->taxincluded;
}
gnc_commodity * gncCustomerGetCurrency (const GncCustomer *cust)
{
- if (!cust) return NULL;
- return cust->currency;
+ if (!cust) return NULL;
+ return cust->currency;
}
gboolean gncCustomerGetActive (const GncCustomer *cust)
{
- if (!cust) return FALSE;
- return cust->active;
+ if (!cust) return FALSE;
+ return cust->active;
}
gnc_numeric gncCustomerGetDiscount (const GncCustomer *cust)
{
- if (!cust) return gnc_numeric_zero();
- return cust->discount;
+ if (!cust) return gnc_numeric_zero();
+ return cust->discount;
}
gnc_numeric gncCustomerGetCredit (const GncCustomer *cust)
{
- if (!cust) return gnc_numeric_zero();
- return cust->credit;
+ if (!cust) return gnc_numeric_zero();
+ return cust->credit;
}
gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer)
{
- if (!customer) return FALSE;
- return customer->taxtable_override;
+ if (!customer) return FALSE;
+ return customer->taxtable_override;
}
GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer)
{
- if (!customer) return NULL;
- return customer->taxtable;
+ if (!customer) return NULL;
+ return customer->taxtable;
}
GList * gncCustomerGetJoblist (const GncCustomer *cust, gboolean show_all)
{
- if (!cust) return NULL;
+ 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);
+ if (show_all)
+ {
+ return (g_list_copy (cust->jobs));
}
- return list;
- }
+ 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));
+ 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;
+ if (!a && !b) return 0;
+ if (!a && b) return 1;
+ if (a && !b) return -1;
- return(strcmp(a->name, b->name));
+ return(strcmp(a->name, b->name));
}
/**
@@ -657,80 +683,99 @@
*/
static void
listen_for_address_events(QofInstance *entity, QofEventId event_type,
- gpointer user_data, gpointer event_data)
+ gpointer user_data, gpointer event_data)
{
- GncCustomer* cust;
+ 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);
+ 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);
+ if (!item) return "failed";
+ return gncCustomerGetName((GncCustomer*)item);
}
static QofObject gncCustomerDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Customer",
- .create = (gpointer)gncCustomerCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = (const char* (*)(gpointer))gncCustomerGetName,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Customer",
+ .create = (gpointer)gncCustomerCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = (const char * (*)(gpointer))gncCustomerGetName,
+ .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 },
- };
+ 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);
+ 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);
+ return qof_book_get_counter (book, _GNC_MOD_NAME);
}
Modified: gnucash/trunk/src/business/business-core/gncCustomer.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncCustomer.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -24,7 +24,7 @@
/** @addtogroup Customer
@{ */
/** @file gncCustomer.h
- @brief Core Customer Interface
+ @brief Core Customer Interface
@author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
*/
@@ -78,7 +78,7 @@
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_CUSTOMER, GncCustomerClass))
GType gnc_customer_get_type(void);
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncCustomer *gncCustomerCreate (QofBook *book);
void gncCustomerDestroy (GncCustomer *customer);
@@ -86,7 +86,7 @@
void gncCustomerCommitEdit (GncCustomer *customer);
/** @} */
-/** @name Set Functions
+/** @name Set Functions
@{ */
void gncCustomerSetID (GncCustomer *customer, const char *id);
@@ -107,10 +107,10 @@
/** @} */
-/** @name Get Functions
+/** @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
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncCustomerP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomerP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncCustomerP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -37,7 +37,7 @@
/** 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
+ * 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);
Modified: gnucash/trunk/src/business/business-core/gncEmployee.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEmployee.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -39,28 +39,28 @@
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);
+ gpointer user_data, gpointer event_data);
-struct _gncEmployee
+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;
+ QofInstance inst;
+ char * id;
+ char * username;
+ GncAddress * addr;
+ gnc_commodity * currency;
+ gboolean active;
- Account * ccard_acc;
+ char * language;
+ char * acl;
+ gnc_numeric workday;
+ gnc_numeric rate;
+
+ Account * ccard_acc;
};
struct _gncEmployeeClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -70,15 +70,16 @@
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);
+ qof_instance_set_dirty(&employee->inst);
+ qof_event_gen (&employee->inst, QOF_EVENT_MODIFY, NULL);
}
/* ============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_USERNAME
+ PROP_USERNAME
};
/* GObject Initialization */
@@ -103,43 +104,45 @@
static void
gnc_employee_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -147,116 +150,117 @@
gnc_employee_class_init (GncEmployeeClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
g_object_class_install_property
- (gobject_class,
- PROP_USERNAME,
- g_param_spec_string ("name",
- "Employee Name",
- "The employee name is an arbitrary string "
- "assigned by the user which provides the employee "
- "name.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_USERNAME,
+ g_param_spec_string ("name",
+ "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;
+ GncEmployee *employee;
- if (!book) return NULL;
+ 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);
- }
+ employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
+ qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);
- qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
+ 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;
- return employee;
+ 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);
+ if (!employee) return;
+ qof_instance_set_destroying(employee, TRUE);
+ gncEmployeeCommitEdit(employee);
}
static void gncEmployeeFree (GncEmployee *employee)
{
- if (!employee) return;
+ if (!employee) return;
- qof_event_gen (&employee->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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);
+ /* qof_instance_release (&employee->inst); */
+ g_object_unref (employee);
}
GncEmployee *
gncCloneEmployee (GncEmployee *from, QofBook *book)
{
- GncEmployee *employee;
- if (!book || !from) return NULL;
+ 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 = 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);
+ 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));
- return employee;
+ qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
+
+ return employee;
}
GncEmployee *
gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
{
- GncEmployee *employee;
- if (!book) return NULL;
+ GncEmployee *employee;
+ if (!book) return NULL;
- employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!employee)
- {
- employee = gncCloneEmployee (from, book);
- }
+ employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!employee)
+ {
+ employee = gncCloneEmployee (from, book);
+ }
- return employee;
+ return employee;
}
/* ============================================================== */
@@ -274,207 +278,214 @@
void gncEmployeeSetID (GncEmployee *employee, const char *id)
{
- if (!employee) return;
- if (!id) return;
- SET_STR(employee, employee->id, id);
- mark_employee (employee);
- gncEmployeeCommitEdit (employee);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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;
+ if (!employee) return NULL;
+ return employee->id;
}
const char * gncEmployeeGetUsername (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->username;
+ if (!employee) return NULL;
+ return employee->username;
}
GncAddress * gncEmployeeGetAddr (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->addr;
+ if (!employee) return NULL;
+ return employee->addr;
}
const char * gncEmployeeGetLanguage (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->language;
+ if (!employee) return NULL;
+ return employee->language;
}
const char * gncEmployeeGetAcl (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->acl;
+ if (!employee) return NULL;
+ return employee->acl;
}
gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee)
{
- if (!employee) return gnc_numeric_zero();
- return employee->workday;
+ if (!employee) return gnc_numeric_zero();
+ return employee->workday;
}
gnc_numeric gncEmployeeGetRate (const GncEmployee *employee)
{
- if (!employee) return gnc_numeric_zero();
- return employee->rate;
+ if (!employee) return gnc_numeric_zero();
+ return employee->rate;
}
gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->currency;
+ if (!employee) return NULL;
+ return employee->currency;
}
gboolean gncEmployeeGetActive (const GncEmployee *employee)
{
- if (!employee) return FALSE;
- return employee->active;
+ if (!employee) return FALSE;
+ return employee->active;
}
Account * gncEmployeeGetCCard (const GncEmployee *employee)
{
- if (!employee) return NULL;
- return employee->ccard_acc;
+ 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));
+ if (!employee) return FALSE;
+ return (qof_instance_get_dirty_flag(employee)
+ || gncAddressIsDirty (employee->addr));
}
void gncEmployeeBeginEdit (GncEmployee *employee)
{
- qof_begin_edit(&employee->inst);
+ qof_begin_edit(&employee->inst);
}
static void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode)
{
- PERR("Employee QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ GncEmployee *employee = (GncEmployee *) inst;
+ gncAddressClearDirty (employee->addr);
}
static void emp_free (QofInstance *inst)
{
- GncEmployee *employee = (GncEmployee *) inst;
- gncEmployeeFree (employee);
+ 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);
+ if (!qof_commit_edit (QOF_INSTANCE(employee))) return;
+ qof_commit_edit_part2 (&employee->inst, gncEmployeeOnError,
+ gncEmployeeOnDone, emp_free);
}
/* ============================================================== */
@@ -482,20 +493,20 @@
int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
{
- if (!a && !b) return 0;
- if (!a && b) return 1;
- if (a && !b) return -1;
+ if (!a && !b) return 0;
+ if (!a && b) return 1;
+ if (a && !b) return -1;
- return(strcmp(a->username, b->username));
+ return(strcmp(a->username, b->username));
}
/* Package-Private functions */
static const char * _gncEmployeePrintable (gpointer item)
{
- GncEmployee *v = item;
- if (!item) return NULL;
- return gncAddressGetName(v->addr);
+ GncEmployee *v = item;
+ if (!item) return NULL;
+ return gncAddressGetName(v->addr);
}
/**
@@ -509,66 +520,76 @@
*/
static void
listen_for_address_events(QofInstance *entity, QofEventId event_type,
- gpointer user_data, gpointer event_data)
+ gpointer user_data, gpointer event_data)
{
- GncEmployee* empl;
+ 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);
+ 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 =
+static QofObject gncEmployeeDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Employee",
- .create = (gpointer)gncEmployeeCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = _gncEmployeePrintable,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Employee",
+ .create = (gpointer)gncEmployeeCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = _gncEmployeePrintable,
+ .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 },
- };
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params);
- return qof_object_register (&gncEmployeeDesc);
+ return qof_object_register (&gncEmployeeDesc);
}
gint64 gncEmployeeNextID (QofBook *book)
{
- return qof_book_get_counter (book, _GNC_MOD_NAME);
+ return qof_book_get_counter (book, _GNC_MOD_NAME);
}
Modified: gnucash/trunk/src/business/business-core/gncEmployee.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployee.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEmployee.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -53,7 +53,7 @@
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_EMPLOYEE, GncEmployeeClass))
GType gnc_employee_get_type(void);
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncEmployee *gncEmployeeCreate (QofBook *book);
void gncEmployeeDestroy (GncEmployee *employee);
@@ -62,7 +62,7 @@
int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b);
/** @} */
-/** @name Set Functions
+/** @name Set Functions
@{ */
void gncEmployeeSetID (GncEmployee *employee, const char *id);
void gncEmployeeSetUsername (GncEmployee *employee, const char *username);
@@ -77,7 +77,7 @@
/** @} */
-/** @name Get Functions
+/** @name Get Functions
@{ */
QofBook * gncEmployeeGetBook (GncEmployee *employee);
const char * gncEmployeeGetID (const GncEmployee *employee);
Modified: gnucash/trunk/src/business/business-core/gncEmployeeP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEmployeeP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEmployeeP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -38,7 +38,7 @@
* 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
+ * 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.
@@ -52,7 +52,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncEntry.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEntry.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -36,69 +36,69 @@
#include "gncInvoice.h"
#include "gncOrder.h"
-struct _gncEntry
+struct _gncEntry
{
- QofInstance inst;
+ QofInstance inst;
- Timespec date;
- Timespec date_entered;
- char * desc;
- char * action;
- char * notes;
- gnc_numeric quantity;
+ 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;
+ /* 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;
+ /* 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;
+ /* employee bill data */
+ GncEntryPaymentType b_payment;
- /* my parent(s) */
- GncOrder * order;
- GncInvoice * invoice;
- GncInvoice * bill;
+ /* my parent(s) */
+ GncOrder * order;
+ GncInvoice * invoice;
+ GncInvoice * bill;
- /* CACHED VALUES */
- gboolean values_dirty;
+ /* 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;
+ /* 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;
+ /* 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;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -110,51 +110,51 @@
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");
+ 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);
+ 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");
+ 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);
+ 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)");
+ 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);
+ 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)");
+ 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);
+ return(FALSE);
}
#undef GNC_RETURN_ON_MATCH
@@ -173,15 +173,16 @@
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);
+ qof_instance_set_dirty(&entry->inst);
+ qof_event_gen (&entry->inst, QOF_EVENT_MODIFY, NULL);
}
/* ================================================================ */
-enum {
+enum
+{
PROP_0,
- PROP_DESCRIPTION
+ PROP_DESCRIPTION
};
/* GObject Initialization */
@@ -206,43 +207,45 @@
static void
gnc_entry_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -250,107 +253,107 @@
gnc_entry_class_init (GncEntryClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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 ();
+ GncEntry *entry;
+ gnc_numeric zero = gnc_numeric_zero ();
- if (!book) return NULL;
+ if (!book) return NULL;
- entry = g_object_new (GNC_TYPE_ENTRY, NULL);
- qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book);
+ 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->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->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->b_price = zero;
+ entry->b_taxable = TRUE;
+ entry->billto.type = GNC_OWNER_CUSTOMER;
+ entry->b_payment = GNC_PAYMENT_CASH;
- entry->values_dirty = TRUE;
+ entry->values_dirty = TRUE;
- qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL);
- return entry;
+ return entry;
}
void gncEntryDestroy (GncEntry *entry)
{
- if (!entry) return;
- qof_instance_set_destroying(entry, TRUE);
- gncEntryCommitEdit(entry);
+ if (!entry) return;
+ qof_instance_set_destroying(entry, TRUE);
+ gncEntryCommitEdit(entry);
}
static void gncEntryFree (GncEntry *entry)
{
- if (!entry) return;
+ if (!entry) return;
- qof_event_gen (&entry->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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);
+ /* qof_instance_release (&entry->inst); */
+ g_object_unref (entry);
}
GncEntry *
gncCloneEntry (GncEntry *from, QofBook *book)
{
- /* XXX unfinished */
- return NULL;
+ /* XXX unfinished */
+ return NULL;
}
GncEntry *
gncEntryObtainTwin (GncEntry *from, QofBook *book)
{
- GncEntry *entry;
- if (!book) return NULL;
+ GncEntry *entry;
+ if (!book) return NULL;
- entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!entry)
- {
- entry = gncCloneEntry (from, book);
- }
+ entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!entry)
+ {
+ entry = gncCloneEntry (from, book);
+ }
- return entry;
+ return entry;
}
@@ -359,372 +362,373 @@
void gncEntrySetDate (GncEntry *entry, Timespec date)
{
- gboolean first_date = FALSE;
- Timespec zero_time = { 0, 0 };
+ 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);
+ 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);
- }
+ /* 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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;
+ 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);
+ 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;
+ 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);
+ 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;
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ if (!entry) return;
+ if (entry->billable == billable) return;
- gncEntryBeginEdit (entry);
- entry->billable = billable;
- mark_entry (entry);
- gncEntryCommitEdit (entry);
+ 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;
+ if (!entry || !billto) return;
+ if (gncOwnerEqual (&entry->billto, billto)) return;
- gncEntryBeginEdit (entry);
- gncOwnerCopy (billto, &entry->billto);
- mark_entry (entry);
- gncEntryCommitEdit (entry);
+ 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);
+ 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);
+ 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);
+ /* 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);
+ 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);
+ 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;
+ 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;
+ 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;
+ 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;
+ /* 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->i_tax_table)
+ gncEntrySetInvTaxTable (dest, src->i_tax_table);
- if (src->b_tax_table)
- gncEntrySetBillTaxTable (dest, src->b_tax_table);
+ if (src->b_tax_table)
+ gncEntrySetBillTaxTable (dest, src->b_tax_table);
- if (src->order)
- gncOrderAddEntry (src->order, dest);
+ if (src->order)
+ gncOrderAddEntry (src->order, dest);
- if (src->invoice)
- gncInvoiceAddEntry (src->invoice, dest);
+ if (src->invoice)
+ gncInvoiceAddEntry (src->invoice, dest);
- if (src->bill)
- gncBillAddEntry (src->bill, dest);
+ if (src->bill)
+ gncBillAddEntry (src->bill, dest);
- dest->values_dirty = TRUE;
- gncEntryCommitEdit (dest);
+ dest->values_dirty = TRUE;
+ gncEntryCommitEdit (dest);
}
/* ================================================================ */
@@ -732,176 +736,180 @@
Timespec gncEntryGetDate (const GncEntry *entry)
{
- Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
- if (!entry) return ts;
- return entry->date;
+ 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;
+ 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;
+ if (!entry) return NULL;
+ return entry->desc;
}
const char * gncEntryGetAction (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->action;
+ if (!entry) return NULL;
+ return entry->action;
}
const char * gncEntryGetNotes (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->notes;
+ if (!entry) return NULL;
+ return entry->notes;
}
gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
{
- if (!entry) return gnc_numeric_zero();
- return entry->quantity;
+ if (!entry) return gnc_numeric_zero();
+ return entry->quantity;
}
/* Customer Invoice */
Account * gncEntryGetInvAccount (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->i_account;
+ if (!entry) return NULL;
+ return entry->i_account;
}
gnc_numeric gncEntryGetInvPrice (const GncEntry *entry)
{
- if (!entry) return gnc_numeric_zero();
- return entry->i_price;
+ 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;
+ if (!entry) return gnc_numeric_zero();
+ return entry->i_discount;
}
GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
{
- if (!entry) return 0;
- return entry->i_disc_type;
+ if (!entry) return 0;
+ return entry->i_disc_type;
}
GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
{
- if (!entry) return 0;
- return entry->i_disc_how;
+ if (!entry) return 0;
+ return entry->i_disc_how;
}
char* qofEntryGetInvDiscType (const GncEntry *entry)
{
- char *type_string;
+ char *type_string;
- if (!entry) return 0;
- type_string = g_strdup(gncAmountTypeToString(entry->i_disc_type));
- return 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;
+ char *type_string;
- if (!entry) return 0;
- type_string = g_strdup(gncEntryDiscountHowToString(entry->i_disc_how));
- return 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;
+ if (!entry) return FALSE;
+ return entry->i_taxable;
}
gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry)
{
- if (!entry) return FALSE;
- return entry->i_taxincluded;
+ if (!entry) return FALSE;
+ return entry->i_taxincluded;
}
GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->i_tax_table;
+ if (!entry) return NULL;
+ return entry->i_tax_table;
}
/* vendor bills */
Account * gncEntryGetBillAccount (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->b_account;
+ if (!entry) return NULL;
+ return entry->b_account;
}
gnc_numeric gncEntryGetBillPrice (const GncEntry *entry)
{
- if (!entry) return gnc_numeric_zero();
- return entry->b_price;
+ if (!entry) return gnc_numeric_zero();
+ return entry->b_price;
}
gboolean gncEntryGetBillTaxable (const GncEntry *entry)
{
- if (!entry) return FALSE;
- return entry->b_taxable;
+ if (!entry) return FALSE;
+ return entry->b_taxable;
}
gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry)
{
- if (!entry) return FALSE;
- return entry->b_taxincluded;
+ if (!entry) return FALSE;
+ return entry->b_taxincluded;
}
GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->b_tax_table;
+ if (!entry) return NULL;
+ return entry->b_tax_table;
}
gboolean gncEntryGetBillable (const GncEntry *entry)
{
- if (!entry) return FALSE;
- return entry->billable;
+ if (!entry) return FALSE;
+ return entry->billable;
}
GncOwner * gncEntryGetBillTo (GncEntry *entry)
{
- if (!entry) return NULL;
- return &entry->billto;
+ if (!entry) return NULL;
+ return &entry->billto;
}
GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry)
{
- if (!entry) return 0;
- return entry->b_payment;
+ if (!entry) return 0;
+ return entry->b_payment;
}
GncInvoice * gncEntryGetInvoice (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->invoice;
+ if (!entry) return NULL;
+ return entry->invoice;
}
GncInvoice * gncEntryGetBill (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->bill;
+ if (!entry) return NULL;
+ return entry->bill;
}
GncOrder * gncEntryGetOrder (const GncEntry *entry)
{
- if (!entry) return NULL;
- return entry->order;
+ if (!entry) return NULL;
+ return entry->order;
}
/* ================================================================ */
@@ -939,428 +947,462 @@
* 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)
+ 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 ();
+ 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;
+ GList * entries = gncTaxTableGetEntries (tax_table);
+ GList * node;
- /* Step 1: compute the aggregate price */
+ /* Step 1: compute the aggregate price */
- aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+ aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_DENOM_LCD);
- /* Step 2: compute the pre-tax aggregate */
+ /* 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);
+ /* 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));
+ 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);
+ /* 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)
+ /* Next, actually compute the pre-tax aggregate value based on the
+ * taxincluded flag.
*/
- 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;
- }
+ 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 */
+ /* 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.
- */
+ /*
+ * 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
- */
+ /*
+ * 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 */
+ 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);
- }
+ 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);
+ 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;
+ /* 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 */
+ case GNC_DISC_POSTTAX:
+ /* compute discount on pretax+taxes */
- if (discount_type == GNC_AMT_TYPE_PERCENT) {
- gnc_numeric after_tax;
+ 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);
- }
+ 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;
+ result = gnc_numeric_sub (pretax, discount, GNC_DENOM_AUTO, GNC_DENOM_LCD);
+ break;
- default:
- g_warning ("unknown DiscountHow value: %d", discount_how);
- }
+ default:
+ g_warning ("unknown DiscountHow value: %d", discount_how);
+ }
- /* Step 4: return the requested results. */
+ /* 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.
- */
+ /* 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 (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;
- }
+ 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) */
+ /* Now... Compute the list of tax values (if the caller wants it) */
- if (tax_value != NULL) {
- GList * taxes = NULL;
+ 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);
+ 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);
+ 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;
- }
+ 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;
}
- *tax_value = taxes;
- }
- return;
+ 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;
+ 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;
+ 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;
+ /* 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->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;
+ 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;
- }
+ /* 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);
+ /* 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 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));
+ /* 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->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;
+ 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)
+ 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);
+ 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);
+ 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);
+ 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);
+ 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());
+ 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);
+ if (!entry) return FALSE;
+ return (qof_instance_get_editlevel(entry) > 0);
}
/* ================================================================ */
void gncEntryBeginEdit (GncEntry *entry)
{
- qof_begin_edit(&entry->inst);
+ qof_begin_edit(&entry->inst);
}
static void gncEntryOnError (QofInstance *entry, QofBackendError errcode)
{
- PERR("Entry QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ 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;
+ int compare;
- if (a == b) return 0;
- if (!a && b) return -1;
- if (a && !b) return 1;
+ 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), &(b->date));
+ if (compare) return compare;
- compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
- 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->desc, b->desc);
+ if (compare) return compare;
- compare = safe_strcmp (a->action, b->action);
- if (compare) return compare;
+ compare = safe_strcmp (a->action, b->action);
+ if (compare) return compare;
- return qof_instance_guid_compare(a, b);
+ return qof_instance_guid_compare(a, b);
}
/* ============================================================= */
/* Object declaration */
-static QofObject gncEntryDesc =
+static QofObject gncEntryDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Order/Invoice/Bill Entry",
- .create = (gpointer)gncEntryCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = NULL,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Order/Invoice/Bill Entry",
+ .create = (gpointer)gncEntryCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = NULL,
+ .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 },
- };
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
- return qof_object_register (&gncEntryDesc);
+ return qof_object_register (&gncEntryDesc);
}
Modified: gnucash/trunk/src/business/business-core/gncEntry.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntry.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEntry.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -34,15 +34,17 @@
typedef struct _gncEntry GncEntry;
typedef struct _gncEntryClass GncEntryClass;
-typedef enum {
- GNC_PAYMENT_CASH = 1,
- GNC_PAYMENT_CARD
+typedef enum
+{
+ GNC_PAYMENT_CASH = 1,
+ GNC_PAYMENT_CARD
} GncEntryPaymentType;
-typedef enum {
- GNC_DISC_PRETAX = 1,
- GNC_DISC_SAMETIME,
- GNC_DISC_POSTTAX
+typedef enum
+{
+ GNC_DISC_PRETAX = 1,
+ GNC_DISC_SAMETIME,
+ GNC_DISC_POSTTAX
} GncDiscountHow;
#ifdef GNUCASH_MAJOR_VERSION
@@ -84,7 +86,7 @@
const char * gncEntryPaymentTypeToString (GncEntryPaymentType type);
gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type);
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncEntry *gncEntryCreate (QofBook *book);
void gncEntryDestroy (GncEntry *entry);
@@ -92,7 +94,7 @@
/* SET FUNCTIONS */
-/** @name Generic (shared) data
+/** @name Generic (shared) data
@{ */
void gncEntrySetDate (GncEntry *entry, Timespec date);
void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
@@ -102,7 +104,7 @@
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
/** @} */
-/** @name Customer Invoices
+/** @name Customer Invoices
@{ */
void gncEntrySetInvAccount (GncEntry *entry, Account *acc);
void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price);
@@ -116,7 +118,7 @@
void qofEntrySetInvDiscHow (GncEntry *entry, const char *type);
/** @} */
-/** @name Vendor Bills (and Employee Expenses)
+/** @name Vendor Bills (and Employee Expenses)
@{ */
void gncEntrySetBillAccount (GncEntry *entry, Account *acc);
void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price);
@@ -127,13 +129,13 @@
void gncEntrySetBillTo (GncEntry *entry, GncOwner *billto);
/** @} */
-/** @name employee-stuff
+/** @name employee-stuff
@{ */
void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type);
/** @} */
/* GET FUNCTIONS */
-/** @name Generic (shared) data
+/** @name Generic (shared) data
@{ */
Timespec gncEntryGetDate (const GncEntry *entry);
Timespec gncEntryGetDateEntered (const GncEntry *entry);
@@ -143,7 +145,7 @@
gnc_numeric gncEntryGetQuantity (const GncEntry *entry);
/** @} */
-/** @name Customer Invoices
+/** @name Customer Invoices
@{ */
Account * gncEntryGetInvAccount (const GncEntry *entry);
gnc_numeric gncEntryGetInvPrice (const GncEntry *entry);
@@ -157,7 +159,7 @@
GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry);
/** @} */
-/** @name Vendor Bills (and Employee Expenses)
+/** @name Vendor Bills (and Employee Expenses)
@{ */
Account * gncEntryGetBillAccount (const GncEntry *entry);
gnc_numeric gncEntryGetBillPrice (const GncEntry *entry);
@@ -172,7 +174,7 @@
void gncEntryCopy (const GncEntry *src, GncEntry *dest);
-/** @name Getting Values
+/** @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
@@ -197,16 +199,16 @@
* 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);
+ 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);
+ 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);
/** @} */
@@ -215,7 +217,7 @@
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
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncEntryP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncEntryP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncEntryP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -54,7 +54,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncInvoice.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -42,37 +42,37 @@
#include "gncInvoiceP.h"
#include "gncOwnerP.h"
-struct _gncInvoice
+struct _gncInvoice
{
- QofInstance inst;
-
- char *id;
- char *notes;
- gboolean active;
+ QofInstance inst;
- char *billing_id;
- char *printname;
- GncBillTerm *terms;
- GList *entries;
- GList *prices;
- GncOwner owner;
- GncOwner billto;
- GncJob *job;
- Timespec date_opened;
- Timespec date_posted;
+ char *id;
+ char *notes;
+ gboolean active;
- gnc_numeric to_charge_amount;
+ char *billing_id;
+ char *printname;
+ GncBillTerm *terms;
+ GList *entries;
+ GList *prices;
+ GncOwner owner;
+ GncOwner billto;
+ GncJob *job;
+ Timespec date_opened;
+ Timespec date_posted;
- gnc_commodity * currency;
+ gnc_numeric to_charge_amount;
- Account *posted_acc;
- Transaction *posted_txn;
- GNCLot *posted_lot;
+ gnc_commodity * currency;
+
+ Account *posted_acc;
+ Transaction *posted_txn;
+ GNCLot *posted_lot;
};
struct _gncInvoiceClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -96,8 +96,8 @@
static void
mark_invoice (GncInvoice *invoice)
{
- qof_instance_set_dirty(&invoice->inst);
- qof_event_gen (&invoice->inst, QOF_EVENT_MODIFY, NULL);
+ qof_instance_set_dirty(&invoice->inst);
+ qof_event_gen (&invoice->inst, QOF_EVENT_MODIFY, NULL);
}
QofBook * gncInvoiceGetBook(GncInvoice *x)
@@ -107,9 +107,10 @@
/* ================================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NOTES
+ PROP_NOTES
};
/* GObject Initialization */
@@ -134,43 +135,45 @@
static void
gnc_invoice_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -178,149 +181,149 @@
gnc_invoice_class_init (GncInvoiceClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ GncInvoice *invoice;
- if (!book) return NULL;
+ if (!book) return NULL;
- invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
- qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
+ 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->id = CACHE_INSERT ("");
+ invoice->notes = CACHE_INSERT ("");
+ invoice->billing_id = CACHE_INSERT ("");
- invoice->billto.type = GNC_OWNER_CUSTOMER;
- invoice->active = TRUE;
+ invoice->billto.type = GNC_OWNER_CUSTOMER;
+ invoice->active = TRUE;
- invoice->to_charge_amount = gnc_numeric_zero();
+ invoice->to_charge_amount = gnc_numeric_zero();
- qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
- return invoice;
+ return invoice;
}
void gncInvoiceDestroy (GncInvoice *invoice)
{
- if (!invoice) return;
- qof_instance_set_destroying(invoice, TRUE);
- gncInvoiceCommitEdit (invoice);
+ if (!invoice) return;
+ qof_instance_set_destroying(invoice, TRUE);
+ gncInvoiceCommitEdit (invoice);
}
static void gncInvoiceFree (GncInvoice *invoice)
{
- if (!invoice) return;
+ if (!invoice) return;
- qof_event_gen (&invoice->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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->printname) g_free (invoice->printname);
- if (invoice->terms)
- gncBillTermDecRef (invoice->terms);
+ if (invoice->terms)
+ gncBillTermDecRef (invoice->terms);
- /* qof_instance_release (&invoice->inst); */
- g_object_unref (invoice);
+ /* qof_instance_release (&invoice->inst); */
+ g_object_unref (invoice);
}
GncInvoice *
gncCloneInvoice (GncInvoice *from, QofBook *book)
{
- GList *node;
- GncInvoice *invoice;
+ GList *node;
+ GncInvoice *invoice;
- if (!book) return NULL;
+ if (!book) return NULL;
- invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
- qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
+ 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->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->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->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->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->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);
- }
+ 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));
+ /* 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;
+ XXX not done * /
+ Transaction * posted_txn;
+ GNCLot * posted_lot;
#endif
- qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
- return invoice;
+ return invoice;
}
GncInvoice *
gncInvoiceObtainTwin (GncInvoice *from, QofBook *book)
{
- GncInvoice *invoice;
- if (!book) return NULL;
+ GncInvoice *invoice;
+ if (!book) return NULL;
- invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!invoice)
- {
- invoice = gncCloneInvoice (from, book);
- }
+ invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!invoice)
+ {
+ invoice = gncCloneInvoice (from, book);
+ }
- return invoice;
+ return invoice;
}
/* ================================================================== */
@@ -328,257 +331,263 @@
void gncInvoiceSetID (GncInvoice *invoice, const char *id)
{
- if (!invoice || !id) return;
- SET_STR (invoice, invoice->id, id);
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ if (!invoice || !billto) return;
+ if (gncOwnerEqual (&invoice->billto, billto)) return;
- gncInvoiceBeginEdit (invoice);
- gncOwnerCopy (billto, &invoice->billto);
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ 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);
+ 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);
+ if (!invoice) return;
+ g_return_if_fail (invoice->posted_txn == NULL);
- gncInvoiceBeginEdit (invoice);
- invoice->posted_txn = txn;
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ 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);
+ if (!invoice) return;
+ g_return_if_fail (invoice->posted_lot == NULL);
- gncInvoiceBeginEdit (invoice);
- invoice->posted_lot = lot;
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ 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);
+ if (!invoice) return;
+ g_return_if_fail (invoice->posted_acc == NULL);
- gncInvoiceBeginEdit (invoice);
- invoice->posted_acc = acc;
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ gncInvoiceBeginEdit (invoice);
+ invoice->posted_acc = acc;
+ mark_invoice (invoice);
+ gncInvoiceCommitEdit (invoice);
}
void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
{
- GncInvoice *old;
+ GncInvoice *old;
- if (!invoice || !entry) return;
+ if (!invoice || !entry) return;
- old = gncEntryGetInvoice (entry);
- if (old == invoice) return; /* I already own this one */
- if (old) gncInvoiceRemoveEntry (old, entry);
+ 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);
+ 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;
+ if (!invoice || !entry) return;
- gncEntrySetInvoice (entry, NULL);
- invoice->entries = g_list_remove (invoice->entries, entry);
- mark_invoice (invoice);
+ gncEntrySetInvoice (entry, NULL);
+ invoice->entries = g_list_remove (invoice->entries, entry);
+ mark_invoice (invoice);
}
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
{
- if (!invoice || !price) return;
+ if (!invoice || !price) return;
- invoice->prices = g_list_prepend(invoice->prices, price);
- mark_invoice (invoice);
+ invoice->prices = g_list_prepend(invoice->prices, price);
+ mark_invoice (invoice);
}
void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price)
{
- if (!invoice || !price) return;
+ if (!invoice || !price) return;
- invoice->prices = g_list_remove (invoice->prices, price);
- mark_invoice (invoice);
+ invoice->prices = g_list_remove (invoice->prices, price);
+ mark_invoice (invoice);
}
void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
{
- GncInvoice *old;
+ GncInvoice *old;
- if (!bill || !entry) return;
+ if (!bill || !entry) return;
- old = gncEntryGetBill (entry);
- if (old == bill) return; /* I already own this one */
- if (old) gncBillRemoveEntry (old, entry);
+ 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);
+ 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;
+ if (!bill || !entry) return;
- gncEntrySetBill (entry, NULL);
- bill->entries = g_list_remove (bill->entries, entry);
- mark_invoice (bill);
+ gncEntrySetBill (entry, NULL);
+ bill->entries = g_list_remove (bill->entries, entry);
+ mark_invoice (bill);
}
void gncBillAddPrice (GncInvoice *bill, GNCPrice *price)
{
- if (!bill || !price) return;
+ if (!bill || !price) return;
- bill->prices = g_list_prepend(bill->prices, price);
- mark_invoice (bill);
+ bill->prices = g_list_prepend(bill->prices, price);
+ mark_invoice (bill);
}
void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price)
{
- if (!bill || !price) return;
+ if (!bill || !price) return;
- bill->prices = g_list_remove (bill->prices, price);
- mark_invoice (bill);
+ 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);
+ if (!invoice) return;
+ invoice->entries = g_list_sort(invoice->entries,
+ (GCompareFunc)gncEntryCompare);
+ mark_invoice(invoice);
}
/* ================================================================== */
@@ -586,881 +595,934 @@
const char * gncInvoiceGetID (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->id;
+ if (!invoice) return NULL;
+ return invoice->id;
}
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return &invoice->owner;
+ if (!invoice) return NULL;
+ return &invoice->owner;
}
static QofInstance*
qofInvoiceGetOwner (GncInvoice *invoice)
{
- GncOwner *owner;
+ GncOwner *owner;
- if(!invoice) { return NULL; }
- owner = &invoice->owner;
- return QOF_INSTANCE(owner);
+ if (!invoice)
+ {
+ return NULL;
+ }
+ owner = &invoice->owner;
+ return QOF_INSTANCE(owner);
}
static QofInstance*
qofInvoiceGetBillTo (GncInvoice *invoice)
{
- GncOwner *billto;
+ GncOwner *billto;
- if(!invoice) { return NULL; }
- billto = &invoice->billto;
- return QOF_INSTANCE(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 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 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);
+ 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;
+ if (!invoice) return NULL;
+ return invoice->terms;
}
const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->billing_id;
+ if (!invoice) return NULL;
+ return invoice->billing_id;
}
const char * gncInvoiceGetNotes (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->notes;
+ if (!invoice) return NULL;
+ return invoice->notes;
}
GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice)
{
- GncOwner *owner;
- g_return_val_if_fail (invoice, GNC_OWNER_NONE);
+ GncOwner *owner;
+ g_return_val_if_fail (invoice, GNC_OWNER_NONE);
- owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
- return (gncOwnerGetType (owner));
+ 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)
+ gboolean use_tax,
+ gboolean use_payment_type, GncEntryPaymentType type)
{
- GList *node;
- gnc_numeric total = gnc_numeric_zero();
- gboolean reverse;
+ GList *node;
+ gnc_numeric total = gnc_numeric_zero();
+ gboolean reverse;
- g_return_val_if_fail (invoice, total);
+ g_return_val_if_fail (invoice, total);
- reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
+ reverse = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
- for (node = gncInvoiceGetEntries(invoice); node; node = node->next) {
- GncEntry *entry = node->data;
- gnc_numeric value, tax;
+ for (node = gncInvoiceGetEntries(invoice); node; node = node->next)
+ {
+ GncEntry *entry = node->data;
+ gnc_numeric value, tax;
- if (use_payment_type && gncEntryGetBillPayment (entry) != type)
- continue;
+ 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");
+ gncEntryGetValue (entry, reverse, &value, NULL, &tax, NULL);
- 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;
+ 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);
+ 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);
+ 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);
+ 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);
+ if (!invoice) return gnc_numeric_zero();
+ return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
}
const char * gncInvoiceGetType (GncInvoice *invoice)
{
- if (!invoice) return NULL;
+ if (!invoice) return NULL;
- switch (gncInvoiceGetOwnerType (invoice)) {
- case GNC_OWNER_CUSTOMER:
- return _("Invoice");
- case GNC_OWNER_VENDOR:
- return _("Bill");
- case GNC_OWNER_EMPLOYEE:
- return _("Expense");
- default:
- return NULL;
- }
+ switch (gncInvoiceGetOwnerType (invoice))
+ {
+ case GNC_OWNER_CUSTOMER:
+ return _("Invoice");
+ case GNC_OWNER_VENDOR:
+ return _("Bill");
+ case GNC_OWNER_EMPLOYEE:
+ return _("Expense");
+ default:
+ return NULL;
+ }
}
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->currency;
+ if (!invoice) return NULL;
+ return invoice->currency;
}
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return &invoice->billto;
+ if (!invoice) return NULL;
+ return &invoice->billto;
}
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->posted_lot;
+ if (!invoice) return NULL;
+ return invoice->posted_lot;
}
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->posted_txn;
+ if (!invoice) return NULL;
+ return invoice->posted_txn;
}
Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->posted_acc;
+ if (!invoice) return NULL;
+ return invoice->posted_acc;
}
gboolean gncInvoiceGetActive (const GncInvoice *invoice)
{
- if (!invoice) return FALSE;
- return invoice->active;
+ if (!invoice) return FALSE;
+ return invoice->active;
}
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
{
- if (!invoice) return gnc_numeric_zero();
- return invoice->to_charge_amount;
+ if (!invoice) return gnc_numeric_zero();
+ return invoice->to_charge_amount;
}
EntryList * gncInvoiceGetEntries (GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->entries;
+ if (!invoice) return NULL;
+ return invoice->entries;
}
GList * gncInvoiceGetPrices(GncInvoice *invoice)
{
- if (!invoice) return NULL;
- return invoice->prices;
+ if (!invoice) return NULL;
+ return invoice->prices;
}
GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity *commodity)
{
- GList *node=g_list_first(invoice->prices);
+ GList *node = g_list_first(invoice->prices);
- while (node != NULL)
- {
- GNCPrice *curr = (GNCPrice*)node->data;
+ while (node != NULL)
+ {
+ GNCPrice *curr = (GNCPrice*)node->data;
- if (gnc_commodity_equal(commodity, gnc_price_get_commodity(curr)))
- return curr;
+ if (gnc_commodity_equal(commodity, gnc_price_get_commodity(curr)))
+ return curr;
- node = g_list_next(node);
- }
+ node = g_list_next(node);
+ }
- return NULL;
+ return NULL;
}
static QofCollection*
qofInvoiceGetEntries (GncInvoice *invoice)
{
- QofCollection *entry_coll;
- GList *list;
- QofInstance *entry;
+ 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;
+ 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;
+ 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;
- }
- }
+ 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
+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);
- }
+ 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;
+ if (!invoice)
+ {
+ return NULL;
+ }
+ return invoice->job;
}
-static void
+static void
qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
{
- if(!invoice) { return; }
- invoice->job = job;
+ if (!invoice)
+ {
+ return;
+ }
+ invoice->job = job;
}
static void
gncInvoiceDetachFromLot (GNCLot *lot)
{
- KvpFrame *kvp;
+ KvpFrame *kvp;
- if (!lot) return;
+ if (!lot) return;
- kvp = gnc_lot_get_slots (lot);
- kvp_frame_set_slot_path (kvp, NULL, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
+ 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;
+ KvpFrame *kvp;
+ KvpValue *value;
- if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
+ if (!invoice || !lot)
+ return;
- 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);
+ 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;
- GUID *guid;
- QofBook *book;
+ KvpFrame *kvp;
+ KvpValue *value;
+ GUID *guid;
+ QofBook *book;
- if (!lot) return NULL;
+ 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;
+ 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);
+ 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;
+ KvpFrame *kvp;
+ KvpValue *value;
- if (invoice->posted_txn) return; /* Cannot reset invoice's txn */
+ if (!invoice || !txn)
+ return;
- 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);
+ 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 *
+GncInvoice *
gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
{
- KvpFrame *kvp;
- KvpValue *value;
- GUID *guid;
- QofBook *book;
+ KvpFrame *kvp;
+ KvpValue *value;
+ GUID *guid;
+ QofBook *book;
- if (!txn) return NULL;
+ 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;
+ 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);
+ guid = kvp_value_get_guid (value);
+ return gncInvoiceLookup(book, guid);
}
-struct lotmatch {
- GncOwner *owner;
- gboolean reverse;
+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);
+ 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 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 there an invoice attached? */
+ if (gncInvoiceGetInvoiceFromLot (lot))
+ return FALSE;
- /* Is it ours? */
- if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
- return FALSE;
- owner = gncOwnerGetEndOwner (&owner_def);
+ /* Is it ours? */
+ if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
+ return FALSE;
+ owner = gncOwnerGetEndOwner (&owner_def);
- return gncOwnerEqual (owner, lm->owner);
+ return gncOwnerEqual (owner, lm->owner);
}
Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
- Timespec *post_date, Timespec *due_date,
- const char * memo, gboolean accumulatesplits)
+ 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;
+ 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;
+ if (!invoice || !acc) return NULL;
- gncInvoiceBeginEdit (invoice);
- book = qof_instance_get_book(invoice);
+ gncInvoiceBeginEdit (invoice);
+ book = qof_instance_get_book(invoice);
- /* Stabilize the Billing Terms of this invoice */
- if (invoice->terms)
- gncInvoiceSetTerms (invoice,
- gncBillTermReturnChild (invoice->terms, TRUE));
+ /* 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 "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));
+ /* 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;
+ /* Find an existing payment-lot for this owner */
+ {
+ LotList *lot_list;
+ struct lotmatch lm;
- lm.reverse = reverse;
- lm.owner = owner;
+ lm.reverse = reverse;
+ lm.owner = owner;
- lot_list = xaccAccountFindOpenLots (acc, gnc_lot_match_owner_payment,
- &lm, NULL);
- if (lot_list)
- lot = lot_list->data;
+ lot_list = xaccAccountFindOpenLots (acc, gnc_lot_match_owner_payment,
+ &lm, NULL);
+ if (lot_list)
+ lot = lot_list->data;
- g_list_free (lot_list);
- }
+ 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);
+ /* 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);
+ 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);
+ /* 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);
+ /* Create a new transaction */
+ txn = xaccMallocTransaction (book);
+ xaccTransBeginEdit (txn);
- name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
+ 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);
+ /* 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);
- }
+ /* 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);
+ 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;
+ /* 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));
+ /* 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);
+ /* 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);
+ /* 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;
+ /* 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? */
+ split = xaccMallocSplit (book);
+ /* set action and memo? */
- xaccSplitSetMemo (split, gncEntryGetDescription (entry));
- xaccSplitSetAction (split, type);
+ 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);
+ /* 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 (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 (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;
+ /* 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);
+ 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
- g_warning ("bad value in our entry");
- }
+ }
+ else
+ total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_DENOM_LCD);
- /* now merge in the TaxValues */
- splitinfo = gncAccountValueAddList (splitinfo, taxes);
+ }
+ else
+ g_warning ("bad value in our entry");
+ }
- /* ... 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");
+ /* now merge in the TaxValues */
+ splitinfo = gncAccountValueAddList (splitinfo, taxes);
- } /* for */
+ /* ... 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");
- /* Iterate through the splitinfo list and generate the splits */
- for (iter = splitinfo; iter; iter = iter->next) {
- Split *split;
- GncAccountValue *acc_val = iter->data;
+ } /* for */
- split = xaccMallocSplit (book);
- /* set action and memo? */
+ /* Iterate through the splitinfo list and generate the splits */
+ for (iter = splitinfo; iter; iter = iter->next)
+ {
+ Split *split;
+ GncAccountValue *acc_val = iter->data;
- xaccSplitSetMemo (split, memo);
- xaccSplitSetAction (split, type);
+ split = xaccMallocSplit (book);
+ /* set action and memo? */
- xaccAccountBeginEdit (acc_val->account);
- xaccAccountInsertSplit (acc_val->account, split);
- xaccAccountCommitEdit (acc_val->account);
- xaccTransAppendSplit (txn, split);
+ xaccSplitSetMemo (split, memo);
+ xaccSplitSetAction (split, type);
- 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));
+ xaccAccountBeginEdit (acc_val->account);
+ xaccAccountInsertSplit (acc_val->account, split);
+ xaccAccountCommitEdit (acc_val->account);
+ xaccTransAppendSplit (txn, split);
- if (price == NULL)
+ if (gnc_commodity_equal(xaccAccountGetCommodity(acc_val->account), invoice->currency))
{
- /*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;
+ xaccSplitSetBaseValue (split, (reverse ? gnc_numeric_neg (acc_val->value)
+ : acc_val->value),
+ invoice->currency);
}
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));
+ /*need to do conversion */
+ GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(acc_val->account));
- xaccSplitSetAmount(split, reverse ? gnc_numeric_neg(converted_amount): converted_amount);
+ 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);
+ /* 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);
+ /* Set memo. action? */
+ xaccSplitSetMemo (split, _("Extra to Charge Card"));
+ xaccSplitSetAction (split, type);
- total = gnc_numeric_sub (total, invoice->to_charge_amount,
- GNC_DENOM_AUTO, GNC_DENOM_LCD);
- }
+ 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);
- /* Now create the Posted split (which is negative -- it's a credit) */
- {
- Split *split = xaccMallocSplit (book);
+ total = gnc_numeric_sub (total, invoice->to_charge_amount,
+ GNC_DENOM_AUTO, GNC_DENOM_LCD);
+ }
- /* 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);
+ /* Now create the Posted split (which is negative -- it's a credit) */
+ {
+ Split *split = xaccMallocSplit (book);
- /* add this split to the lot */
- gnc_lot_add_split (lot, split);
- }
+ /* Set action/memo */
+ xaccSplitSetMemo (split, memo);
+ xaccSplitSetAction (split, type);
- /* Now attach this invoice to the txn, lot, and account */
- gncInvoiceAttachToLot (invoice, lot);
- gncInvoiceAttachToTxn (invoice, txn);
- gncInvoiceSetPostedAcc (invoice, acc);
+ xaccAccountBeginEdit (acc);
+ xaccAccountInsertSplit (acc, split);
+ xaccAccountCommitEdit (acc);
+ xaccTransAppendSplit (txn, split);
+ xaccSplitSetBaseValue (split, (reverse ? total : gnc_numeric_neg (total)),
+ invoice->currency);
- xaccTransSetReadOnly (txn, _("Generated from an invoice. Try unposting the invoice."));
- xaccTransCommitEdit (txn);
+ /* add this split to the lot */
+ gnc_lot_add_split (lot, split);
+ }
- gncAccountValueDestroy (splitinfo);
+ /* Now attach this invoice to the txn, lot, and account */
+ gncInvoiceAttachToLot (invoice, lot);
+ gncInvoiceAttachToTxn (invoice, txn);
+ gncInvoiceSetPostedAcc (invoice, acc);
- /* 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");
+ xaccTransSetReadOnly (txn, _("Generated from an invoice. Try unposting the invoice."));
+ xaccTransCommitEdit (txn);
- t2 = xaccMallocTransaction (book);
- lot2 = gnc_lot_new (book);
- gnc_lot_begin_edit (lot2);
- gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)),
- lot2);
-
- xaccTransBeginEdit (t2);
- xaccAccountBeginEdit (acc);
+ gncAccountValueDestroy (splitinfo);
- /* Set Transaction Description (Owner Name), Currency */
- xaccTransSetDescription (t2, name ? name : "");
- xaccTransSetCurrency (t2, invoice->currency);
+ /* 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);
- /* Entered and Posted at date */
- xaccTransSetDateEnteredSecs (t2, time(NULL));
- if (post_date)
- xaccTransSetDatePostedTS (t2, post_date);
+ 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");
- /* 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);
+ t2 = xaccMallocTransaction (book);
+ lot2 = gnc_lot_new (book);
+ gnc_lot_begin_edit (lot2);
+ gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)),
+ lot2);
- /* 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);
+ xaccTransBeginEdit (t2);
+ xaccAccountBeginEdit (acc);
- gnc_lot_commit_edit (lot2);
- xaccTransCommitEdit (t2);
- xaccAccountCommitEdit (acc);
- }
+ /* Set Transaction Description (Owner Name), Currency */
+ xaccTransSetDescription (t2, name ? name : "");
+ xaccTransSetCurrency (t2, invoice->currency);
- gnc_lot_commit_edit (lot);
- gncInvoiceCommitEdit (invoice);
+ /* Entered and Posted at date */
+ xaccTransSetDateEnteredSecs (t2, time(NULL));
+ if (post_date)
+ xaccTransSetDatePostedTS (t2, post_date);
- return txn;
+ /* 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;
+ Transaction *txn;
+ GNCLot *lot;
- if (!invoice) return FALSE;
- if (!gncInvoiceIsPosted (invoice)) return FALSE;
+ if (!invoice) return FALSE;
+ if (!gncInvoiceIsPosted (invoice)) return FALSE;
- txn = gncInvoiceGetPostedTxn (invoice);
- g_return_val_if_fail (txn, FALSE);
+ txn = gncInvoiceGetPostedTxn (invoice);
+ g_return_val_if_fail (txn, FALSE);
- lot = gncInvoiceGetPostedLot (invoice);
- g_return_val_if_fail (lot, FALSE);
+ lot = gncInvoiceGetPostedLot (invoice);
+ g_return_val_if_fail (lot, FALSE);
- /* Destroy the Posted Transaction */
- xaccTransClearReadOnly (txn);
- xaccTransBeginEdit (txn);
- xaccTransDestroy (txn);
- xaccTransCommitEdit (txn);
+ /* 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);
+ /* 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);
+ /* 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);
+ /* 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;
+ 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;
+ /* 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;
+ 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);
+ gncEntryBeginEdit(entry);
+ if (reverse)
+ gncEntrySetInvTaxTable(entry,
+ gncTaxTableGetParent(gncEntryGetInvTaxTable(entry)));
+ else
+ gncEntrySetBillTaxTable(entry,
+ gncTaxTableGetParent(gncEntryGetBillTaxTable(entry)));
+ gncEntryCommitEdit(entry);
+ }
}
- }
- mark_invoice (invoice);
- gncInvoiceCommitEdit (invoice);
+ mark_invoice (invoice);
+ gncInvoiceCommitEdit (invoice);
- return TRUE;
+ return TRUE;
}
static gboolean
gnc_lot_match_invoice_owner (GNCLot *lot, gpointer user_data)
{
- GncOwner owner_def, *owner, *this_owner = user_data;
- GncInvoice *invoice;
+ 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);
- }
+ /* 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);
+ return gncOwnerEqual (owner, this_owner);
}
static gint
gnc_lot_sort_func (GNCLot *a, GNCLot *b)
{
- GncInvoice *ia, *ib;
- Timespec da, db;
+ GncInvoice *ia, *ib;
+ Timespec da, db;
- ia = gncInvoiceGetInvoiceFromLot (a);
- ib = gncInvoiceGetInvoiceFromLot (b);
+ ia = gncInvoiceGetInvoiceFromLot (a);
+ ib = gncInvoiceGetInvoiceFromLot (b);
- da = gncInvoiceGetDateDue (ia);
- db = gncInvoiceGetDateDue (ib);
+ da = gncInvoiceGetDateDue (ia);
+ db = gncInvoiceGetDateDue (ib);
- return timespec_cmp (&da, &db);
+ return timespec_cmp (&da, &db);
}
/*
@@ -1472,263 +1534,276 @@
*/
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)
+ 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;
+ 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);
+ /* 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);
+ /* 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);
+ 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);
+ /* 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);
+ /* 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));
- }
+ 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.
- */
+ /* 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);
+ 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;
+ /* 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);
+ 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;
+ /* 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;
+ 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;
- }
+ /* 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);
+ balance = gnc_lot_get_balance (lot);
- if (!reverse)
- balance = gnc_numeric_neg (balance);
+ 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 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;
- }
+ /*
+ * 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);
+ /* 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);
+ /* 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);
+ /* 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;
- }
+ if (gnc_numeric_zero_p (payment_value))
+ break;
+ }
- g_list_free (fifo);
+ 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);
+ /* 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);
}
- 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);
- xaccAccountCommitEdit (posted_acc);
+ /* Commit this new transaction */
+ xaccTransCommitEdit (txn);
- /* Commit this new transaction */
- xaccTransCommitEdit (txn);
-
- return 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;
+ 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));
+ 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);
+ 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);
+ qof_begin_edit(&invoice->inst);
}
static void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("Invoice QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ 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;
+ int compare;
- if (a == b) return 0;
- if (!a && b) return -1;
- if (a && !b) return 1;
+ 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 = 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_opened), &(b->date_opened));
+ if (compare) return compare;
- compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
- if (compare) return compare;
+ compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
+ if (compare) return compare;
- return qof_instance_guid_compare(a, b);
+ return qof_instance_guid_compare(a, b);
}
/* ============================================================= */
@@ -1736,119 +1811,132 @@
static const char * _gncInvoicePrintable (gpointer obj)
{
- GncInvoice *invoice = obj;
+ GncInvoice *invoice = obj;
- g_return_val_if_fail (invoice, NULL);
+ g_return_val_if_fail (invoice, NULL);
- if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL) {
- if (invoice->printname) g_free (invoice->printname);
+ 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)") : "");
- }
+ invoice->printname =
+ g_strdup_printf ("%s%s", invoice->id,
+ gncInvoiceIsPosted (invoice) ? _(" (posted)") : "");
+ }
- return invoice->printname;
+ return invoice->printname;
}
-static QofObject gncInvoiceDesc =
+static QofObject gncInvoiceDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Invoice",
- .create = (gpointer)gncInvoiceCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = _gncInvoicePrintable,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Invoice",
+ .create = (gpointer)gncInvoiceCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = _gncInvoicePrintable,
+ .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 },
- };
+ static QofParam params[] =
+ {
+ {
+ INVOICE_FROM_LOT, _GNC_MOD_NAME,
+ (QofAccessFunc)gncInvoiceGetInvoiceFromLot, NULL
+ },
+ { NULL },
+ };
- qof_class_register (GNC_ID_LOT, NULL, params);
+ 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 },
- };
+ static QofParam params[] =
+ {
+ {
+ INVOICE_FROM_TXN, _GNC_MOD_NAME,
+ (QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL
+ },
+ { NULL },
+ };
- qof_class_register (GNC_ID_TRANS, NULL, params);
+ 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 },
- };
+ 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 ();
+ 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);
+ /* 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))) {
+ 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;
+ nextID = qof_book_get_counter (book, "gncBill");
+ break;
case GNC_OWNER_EMPLOYEE:
- nextID = qof_book_get_counter (book, "gncExpVoucher");
- break;
+ nextID = qof_book_get_counter (book, "gncExpVoucher");
+ break;
default:
- nextID = qof_book_get_counter (book, _GNC_MOD_NAME);
- break;
- }
- return nextID;
+ nextID = qof_book_get_counter (book, _GNC_MOD_NAME);
+ break;
+ }
+ return nextID;
}
Modified: gnucash/trunk/src/business/business-core/gncInvoice.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoice.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncInvoice.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -23,12 +23,12 @@
@{ */
/** @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,
+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
+ @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>
*/
@@ -64,13 +64,13 @@
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
GType gnc_invoice_get_type(void);
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncInvoice *gncInvoiceCreate (QofBook *book);
void gncInvoiceDestroy (GncInvoice *invoice);
/** @} */
-/** @name Set Functions
+/** @name Set Functions
@{ */
void gncInvoiceSetID (GncInvoice *invoice, const char *id);
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
@@ -101,7 +101,7 @@
*/
void gncInvoiceSortEntries (GncInvoice *invoice);
-/** @name Get Functions
+/** @name Get Functions
@{ */
const char * gncInvoiceGetID (const GncInvoice *invoice);
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
@@ -112,7 +112,7 @@
const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
const char * gncInvoiceGetNotes (const GncInvoice *invoice);
GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
-const char * gncInvoiceGetType (GncInvoice *invoice);
+const char * gncInvoiceGetType (GncInvoice *invoice);
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
@@ -141,8 +141,8 @@
*/
Transaction *
gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
- Timespec *posted_date, Timespec *due_date,
- const char *memo, gboolean accumulatesplits);
+ Timespec *posted_date, Timespec *due_date,
+ const char *memo, gboolean accumulatesplits);
/**
* UNpost this invoice. This will destroy the posted transaction and
@@ -168,9 +168,9 @@
*/
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);
+ 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 */
@@ -180,7 +180,7 @@
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
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncInvoiceP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncInvoiceP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncInvoiceP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -44,9 +44,9 @@
/** 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.
+ * 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
+ * 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.
@@ -60,7 +60,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncJob.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncJob.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncJob.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -36,19 +36,19 @@
#include "gncJobP.h"
#include "gncOwnerP.h"
-struct _gncJob
+struct _gncJob
{
- QofInstance inst;
- char * id;
- char * name;
- char * desc;
- GncOwner owner;
- gboolean active;
+ QofInstance inst;
+ char * id;
+ char * name;
+ char * desc;
+ GncOwner owner;
+ gboolean active;
};
struct _gncJobClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -61,15 +61,16 @@
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);
+ qof_instance_set_dirty(&job->inst);
+ qof_event_gen (&job->inst, QOF_EVENT_MODIFY, NULL);
}
/* ================================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -94,43 +95,45 @@
static void
gnc_job_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GncJob *job;
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -138,113 +141,114 @@
gnc_job_class_init (GncJobClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ GncJob *job;
- if (!book) return NULL;
+ if (!book) return NULL;
- job = g_object_new (GNC_TYPE_JOB, NULL);
- qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
+ 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;
+ 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);
+ /* GncOwner not initialized */
+ qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
- return job;
+ 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;
+ GncJob *job;
- job->owner = gncCloneOwner(&from->owner, book);
+ if (!book) return NULL;
- qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
-
- return job;
+ 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);
+ if (!job) return;
+ qof_instance_set_destroying(job, TRUE);
+ gncJobCommitEdit (job);
}
static void gncJobFree (GncJob *job)
{
- if (!job) return;
+ if (!job) return;
- qof_event_gen (&job->inst, QOF_EVENT_DESTROY, NULL);
+ qof_event_gen (&job->inst, QOF_EVENT_DESTROY, NULL);
- CACHE_REMOVE (job->id);
- CACHE_REMOVE (job->name);
- CACHE_REMOVE (job->desc);
+ 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;
- }
+ 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);
+ /* 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;
+ GncJob *job;
+ if (!from) return NULL;
+
+ job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!job)
+ {
+ job = gncCloneJob (from, book);
+ }
+ return job;
}
/* ================================================================== */
@@ -262,120 +266,126 @@
void gncJobSetID (GncJob *job, const char *id)
{
- if (!job) return;
- if (!id) return;
- SET_STR(job, job->id, id);
- mark_job (job);
- gncJobCommitEdit (job);
+ 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);
+ 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);
+ 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;
+ 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;
- }
+ switch (gncOwnerGetType (owner))
+ {
+ case GNC_OWNER_CUSTOMER:
+ case GNC_OWNER_VENDOR:
+ break;
+ default:
+ PERR("Unsupported Owner type: %d", gncOwnerGetType(owner));
+ return;
+ }
- gncJobBeginEdit (job);
+ 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;
- }
+ 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));
+ 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;
- }
+ 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);
+ 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);
+ 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);
+ 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);
+ qof_begin_edit(&job->inst);
}
static void gncJobOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("Job QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ if (!qof_commit_edit (QOF_INSTANCE(job))) return;
+ qof_commit_edit_part2 (&job->inst, gncJobOnError,
+ gncJobOnDone, job_free);
}
/* ================================================================== */
@@ -383,49 +393,53 @@
const char * gncJobGetID (const GncJob *job)
{
- if (!job) return NULL;
- return job->id;
+ if (!job) return NULL;
+ return job->id;
}
const char * gncJobGetName (const GncJob *job)
{
- if (!job) return NULL;
- return job->name;
+ if (!job) return NULL;
+ return job->name;
}
const char * gncJobGetReference (const GncJob *job)
{
- if (!job) return NULL;
- return job->desc;
+ if (!job) return NULL;
+ return job->desc;
}
GncOwner * gncJobGetOwner (GncJob *job)
{
- if (!job) return NULL;
- return &(job->owner);
+ if (!job) return NULL;
+ return &(job->owner);
}
gboolean gncJobGetActive (const GncJob *job)
{
- if (!job) return FALSE;
- return job->active;
+ if (!job) return FALSE;
+ return job->active;
}
static QofInstance*
qofJobGetOwner (GncJob *job)
{
- if(!job) { return NULL; }
- return QOF_INSTANCE(qofOwnerGetOwner(&job->owner));
+ 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;
+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));
+ return (safe_strcmp(a->id, b->id));
}
/* ================================================================== */
@@ -433,57 +447,64 @@
static const char * _gncJobPrintable (gpointer item)
{
- GncJob *c;
- if (!item) return NULL;
- c = item;
- return c->name;
+ GncJob *c;
+ if (!item) return NULL;
+ c = item;
+ return c->name;
}
-static QofObject gncJobDesc =
+static QofObject gncJobDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Job",
- .create = (gpointer)gncJobCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = _gncJobPrintable,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Job",
+ .create = (gpointer)gncJobCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = _gncJobPrintable,
+ .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 },
+ 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 },
+ { JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL },
#else
- { JOB_OWNER, QOF_TYPE_CHOICE, (QofAccessFunc)qofJobGetOwner, (QofSetterFunc)qofJobSetOwner },
+ { 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 },
- };
+ { 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; }
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
#ifdef GNUCASH_MAJOR_VERSION
- qofJobGetOwner(NULL);
- qofJobSetOwner(NULL, NULL);
+ qofJobGetOwner(NULL);
+ qofJobSetOwner(NULL, NULL);
#endif
- return qof_object_register (&gncJobDesc);
+ return qof_object_register (&gncJobDesc);
}
gint64 gncJobNextID (QofBook *book)
{
- return qof_book_get_counter (book, _GNC_MOD_NAME);
+ return qof_book_get_counter (book, _GNC_MOD_NAME);
}
Modified: gnucash/trunk/src/business/business-core/gncOrder.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOrder.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -37,25 +37,25 @@
#include "gncOwner.h"
#include "gncOwnerP.h"
-struct _gncOrder
+struct _gncOrder
{
- QofInstance inst;
+ QofInstance inst;
- char * id;
- char * notes;
- gboolean active;
+ char * id;
+ char * notes;
+ gboolean active;
- char * reference;
- char * printname;
- GncOwner owner;
- GList * entries;
- Timespec opened;
- Timespec closed;
+ char * reference;
+ char * printname;
+ GncOwner owner;
+ GList * entries;
+ Timespec opened;
+ Timespec closed;
};
struct _gncOrderClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -75,15 +75,16 @@
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);
+ qof_instance_set_dirty(&order->inst);
+ qof_event_gen (&order->inst, QOF_EVENT_MODIFY, NULL);
}
/* =============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NOTES
+ PROP_NOTES
};
/* GObject Initialization */
@@ -108,43 +109,45 @@
static void
gnc_order_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -152,118 +155,118 @@
gnc_order_class_init (GncOrderClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ GncOrder *order;
- if (!book) return NULL;
+ if (!book) return NULL;
- order = g_object_new (GNC_TYPE_ORDER, NULL);
- qof_instance_init_data (&order->inst, _GNC_MOD_NAME, book);
+ 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->id = CACHE_INSERT ("");
+ order->notes = CACHE_INSERT ("");
+ order->reference = CACHE_INSERT ("");
- order->active = TRUE;
+ order->active = TRUE;
- qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
- return order;
+ return order;
}
void gncOrderDestroy (GncOrder *order)
{
- if (!order) return;
- qof_instance_set_destroying(order, TRUE);
- gncOrderCommitEdit (order);
+ if (!order) return;
+ qof_instance_set_destroying(order, TRUE);
+ gncOrderCommitEdit (order);
}
static void gncOrderFree (GncOrder *order)
{
- if (!order) return;
+ if (!order) return;
- qof_event_gen (&order->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ g_list_free (order->entries);
+ CACHE_REMOVE (order->id);
+ CACHE_REMOVE (order->notes);
+ CACHE_REMOVE (order->reference);
- if (order->printname) g_free (order->printname);
+ if (order->printname) g_free (order->printname);
- /* qof_instance_release (&order->inst); */
- g_object_unref (order);
+ /* qof_instance_release (&order->inst); */
+ g_object_unref (order);
}
GncOrder *
gncCloneOrder (GncOrder *from, QofBook *book)
{
- GList *node;
- GncOrder *order;
+ GList *node;
+ GncOrder *order;
- if (!book) return NULL;
+ 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 = 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->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->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->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);
- }
+ 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);
+ qof_event_gen (&order->inst, QOF_EVENT_CREATE, NULL);
- return order;
+ return order;
}
GncOrder *
gncOrderObtainTwin (GncOrder *from, QofBook *book)
{
- GncOrder *order;
- if (!book) return NULL;
+ GncOrder *order;
+ if (!book) return NULL;
- order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!order)
- {
- order = gncCloneOrder (from, book);
- }
+ order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!order)
+ {
+ order = gncCloneOrder (from, book);
+ }
- return order;
+ return order;
}
/* =============================================================== */
@@ -271,264 +274,270 @@
void gncOrderSetID (GncOrder *order, const char *id)
{
- if (!order || !id) return;
- SET_STR (order, order->id, id);
- mark_order (order);
- gncOrderCommitEdit (order);
+ 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;
+ if (!order || !owner) return;
+ if (gncOwnerEqual (&order->owner, owner)) return;
- gncOrderBeginEdit (order);
- gncOwnerCopy (owner, &order->owner);
- mark_order (order);
- gncOrderCommitEdit (order);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ GncOrder *old;
- if (!order || !entry) return;
+ if (!order || !entry) return;
- old = gncEntryGetOrder (entry);
- if (old == order) return; /* I already own it */
- if (old) gncOrderRemoveEntry (old, entry);
+ 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);
+ 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);
+ /* 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;
+ if (!order || !entry) return;
- gncEntrySetOrder (entry, NULL);
- order->entries = g_list_remove (order->entries, entry);
- mark_order (order);
+ 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;
+ if (!order) return NULL;
+ return order->id;
}
GncOwner * gncOrderGetOwner (GncOrder *order)
{
- if (!order) return NULL;
- return &order->owner;
+ 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 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;
+ 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;
+ if (!order) return NULL;
+ return order->notes;
}
const char * gncOrderGetReference (const GncOrder *order)
{
- if (!order) return NULL;
- return order->reference;
+ if (!order) return NULL;
+ return order->reference;
}
gboolean gncOrderGetActive (const GncOrder *order)
{
- if (!order) return FALSE;
- return order->active;
+ if (!order) return FALSE;
+ return order->active;
}
/* Get the list Entries */
GList * gncOrderGetEntries (GncOrder *order)
{
- if (!order) return NULL;
- return order->entries;
+ 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;
+ 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);
+ qof_begin_edit(&order->inst);
}
static void gncOrderOnError (QofInstance *order, QofBackendError errcode)
{
- PERR("Order QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ 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;
+ int compare;
- if (a == b) return 0;
- if (!a && b) return -1;
- if (a && !b) return 1;
+ 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 = 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->opened), &(b->opened));
+ if (compare) return compare;
- compare = timespec_cmp (&(a->closed), &(b->closed));
- if (compare) return compare;
+ compare = timespec_cmp (&(a->closed), &(b->closed));
+ if (compare) return compare;
- return qof_instance_guid_compare(a, b);
+ return qof_instance_guid_compare(a, b);
}
/* =========================================================== */
/* Package-Private functions */
-static const char *
+static const char *
_gncOrderPrintable (gpointer obj)
{
- GncOrder *order = obj;
+ GncOrder *order = obj;
- g_return_val_if_fail (order, NULL);
+ g_return_val_if_fail (order, NULL);
- if (qof_instance_get_dirty_flag(order) || order->printname == NULL) {
- if (order->printname) g_free (order->printname);
+ 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)") : "");
- }
+ order->printname =
+ g_strdup_printf ("%s%s", order->id,
+ gncOrderIsClosed (order) ? _(" (closed)") : "");
+ }
- return order->printname;
+ return order->printname;
}
static QofObject gncOrderDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Order",
- .create = (gpointer)gncOrderCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = _gncOrderPrintable,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Order",
+ .create = (gpointer)gncOrderCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = _gncOrderPrintable,
+ .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 },
- };
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params);
- return qof_object_register (&gncOrderDesc);
+ return qof_object_register (&gncOrderDesc);
}
gint64 gncOrderNextID (QofBook *book)
{
- return qof_book_get_counter (book, _GNC_MOD_NAME);
+ return qof_book_get_counter (book, _GNC_MOD_NAME);
}
Modified: gnucash/trunk/src/business/business-core/gncOrder.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrder.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOrder.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -96,7 +96,7 @@
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
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncOrderP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOrderP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOrderP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -49,7 +49,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncOrder * gncOrderObtainTwin (GncOrder *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/gncOwner.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOwner.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -48,436 +48,461 @@
GncOwner * gncOwnerCreate (void)
{
- GncOwner *o;
+ GncOwner *o;
- o = g_new0 (GncOwner, 1);
- o->type = GNC_OWNER_NONE;
- return o;
+ o = g_new0 (GncOwner, 1);
+ o->type = GNC_OWNER_NONE;
+ return o;
}
void gncOwnerDestroy (GncOwner *owner)
{
- if (!owner) return;
- g_free (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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ if (!owner) return GNC_OWNER_NONE;
+ return owner->type;
}
QofIdType
qofOwnerGetType(const GncOwner *owner)
{
- QofIdType type;
+ 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;
+ 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;
+ 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;
+ 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);
- }
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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));
- }
+ 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));
+ 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)
- {
+ GncOwner owner = { GNC_OWNER_NONE };
+ if (!from) return owner;
+ owner.type = from->type;
+ switch (from->type)
+ {
case GNC_OWNER_NONE:
- return owner;
+ return owner;
case GNC_OWNER_UNDEFINED:
- owner.owner.undefined = from->owner.undefined; /* XXX probably wrong ! */
- return owner;
+ 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;
+ owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book);
+ return owner;
case GNC_OWNER_JOB:
- owner.owner.job = gncJobObtainTwin (from->owner.job, book);
- return owner;
+ owner.owner.job = gncJobObtainTwin (from->owner.job, book);
+ return owner;
case GNC_OWNER_VENDOR:
- owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book);
- return owner;
+ owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book);
+ return owner;
case GNC_OWNER_EMPLOYEE:
- owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book);
- return owner;
+ owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book);
+ return owner;
default:
- return owner;
- }
+ 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);
+ 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));
- }
+ 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 GUID * gncOwnerGetGUID (const GncOwner *owner)
{
- if (!owner) return NULL;
+ 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));
- }
+ 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));
+ }
}
GUID gncOwnerRetGUID (GncOwner *owner)
{
- const GUID *guid = gncOwnerGetGUID (owner);
- if (guid)
- return *guid;
- return *guid_null ();
+ const GUID *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);
- }
+ 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 && !b) return 0;
+ if (!a && b) return 1;
+ if (a && !b) return -1;
- if (a->type != b->type)
- return (a->type - b->type);
+ 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);
- }
+ 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 GUID * gncOwnerGetEndGUID (GncOwner *owner)
{
- if (!owner) return NULL;
- owner = gncOwnerGetEndOwner (owner);
- return gncOwnerGetGUID (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;
+ KvpFrame *kvp;
+ KvpValue *value;
- kvp = gnc_lot_get_slots (lot);
+ if (!owner || !lot)
+ return;
- 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);
+ kvp = gnc_lot_get_slots (lot);
- 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);
+ 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;
- GUID *guid;
- QofBook *book;
- GncOwnerType type;
+ KvpFrame *kvp;
+ KvpValue *value;
+ GUID *guid;
+ QofBook *book;
+ GncOwnerType type;
- if (!lot || !owner) return FALSE;
+ if (!lot || !owner) return FALSE;
- book = gnc_lot_get_book (lot);
- kvp = gnc_lot_get_slots (lot);
+ 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;
+ value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
+ if (!value) return FALSE;
- type = kvp_value_get_gint64 (value);
+ type = kvp_value_get_gint64 (value);
- value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
- if (!value) return FALSE;
+ 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;
+ 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);
+ 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);
+ if (!owner) return FALSE;
+ return (owner->owner.undefined != NULL);
}
KvpFrame* gncOwnerGetSlots(GncOwner* owner)
{
- if (!owner) return NULL;
+ 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;
- }
+ 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.
@@ -486,67 +511,76 @@
static GncOwner *
owner_from_lot (GNCLot *lot)
{
- static GncOwner owner;
+ static GncOwner owner;
- if (!lot) return NULL;
- if (gncOwnerGetOwnerFromLot (lot, &owner))
- return &owner;
+ if (!lot) return NULL;
+ if (gncOwnerGetOwnerFromLot (lot, &owner))
+ return &owner;
- return NULL;
+ return NULL;
}
static void
reg_lot (void)
{
- static QofParam params[] = {
- { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL },
- { NULL },
- };
+ static QofParam params[] =
+ {
+ { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL },
+ { NULL },
+ };
- qof_class_register (GNC_ID_LOT, NULL, params);
+ qof_class_register (GNC_ID_LOT, NULL, params);
}
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid)
{
- if (!book || !owner || !type || !guid) return FALSE;
+ 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;
+ 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 },
- };
+ 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 ();
+ qof_class_register (GNC_ID_OWNER, (QofSortFunc)gncOwnerCompare, params);
+ reg_lot ();
- return TRUE;
+ return TRUE;
}
Modified: gnucash/trunk/src/business/business-core/gncOwner.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOwner.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -42,16 +42,17 @@
#include "gncJob.h"
#include "gncVendor.h"
#include "gncEmployee.h"
-#include "gnc-lot.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;
+typedef enum
+{
+ GNC_OWNER_NONE ,
+ GNC_OWNER_UNDEFINED ,
+ GNC_OWNER_CUSTOMER ,
+ GNC_OWNER_JOB ,
+ GNC_OWNER_VENDOR ,
+ GNC_OWNER_EMPLOYEE ,
+} GncOwnerType;
/** \name QOF handling
@@ -75,16 +76,18 @@
#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. */
+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 */
Modified: gnucash/trunk/src/business/business-core/gncOwnerP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwnerP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncOwnerP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,5 +1,5 @@
/********************************************************************\
- * gncOwnerP.h -- Business Interface: Object OWNERs private file *
+ * 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 *
Modified: gnucash/trunk/src/business/business-core/gncTaxTable.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -32,38 +32,38 @@
#include "gncTaxTableP.h"
-struct _gncTaxTable
+struct _gncTaxTable
{
- QofInstance inst;
- char * name;
- GncTaxTableEntryList* entries;
- Timespec modtime; /* internal date of last modtime */
+ 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 */
+ /* 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;
+ QofInstanceClass parent_class;
};
-struct _gncTaxTableEntry
+struct _gncTaxTableEntry
{
- GncTaxTable * table;
- Account * account;
- GncAmountType type;
- gnc_numeric amount;
+ GncTaxTable * table;
+ Account * account;
+ GncAmountType type;
+ gnc_numeric amount;
};
-struct _book_info
+struct _book_info
{
- GList * tables; /* visible tables */
+ GList * tables; /* visible tables */
};
static GncTaxTableEntry * CloneTaxEntry (const GncTaxTableEntry*, QofBook *);
@@ -78,30 +78,30 @@
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");
+ 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);
+ 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");
+ 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);
+ 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) \
@@ -109,24 +109,24 @@
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)");
+ 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);
+ 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)");
+ 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);
+ return(FALSE);
}
#undef GNC_RETURN_ON_MATCH
@@ -148,67 +148,68 @@
static inline void
mark_table (GncTaxTable *table)
{
- qof_instance_set_dirty(&table->inst);
- qof_event_gen (&table->inst, QOF_EVENT_MODIFY, NULL);
+ qof_instance_set_dirty(&table->inst);
+ qof_event_gen (&table->inst, QOF_EVENT_MODIFY, NULL);
}
-static inline void
+static inline void
maybe_resort_list (GncTaxTable *table)
{
- struct _book_info *bi;
+ 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);
+ 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));
+ 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,
+ 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);
+ 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);
+ 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);
+ 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);
+ g_return_if_fail(table);
+ g_return_if_fail(child);
- if (qof_instance_get_destroying(table)) return;
+ if (qof_instance_get_destroying(table)) return;
- table->children = g_list_remove(table->children, child);
+ table->children = g_list_remove(table->children, child);
}
/* =============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -233,43 +234,45 @@
static void
gnc_taxtable_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -277,185 +280,186 @@
gnc_taxtable_class_init (GncTaxTableClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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 *
+GncTaxTable *
gncTaxTableCreate (QofBook *book)
{
- GncTaxTable *table;
- if (!book) return NULL;
+ 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;
+ 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 *
+GncTaxTable *
gncCloneTaxTable (GncTaxTable *from, QofBook *book)
{
- GList *node;
- GncTaxTable *table;
- if (!book) return NULL;
+ 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 = 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->refcount = 0;
+ table->name = CACHE_INSERT (from->name);
+ table->modtime = from->modtime;
+ table->invisible = from->invisible;
- /* 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);
- }
+ table->refcount = 0;
- /* 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);
- }
+ /* 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);
+ }
- addObj (table);
- qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
- return table;
+ /* 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;
+ GncTaxTable *table;
+ if (!from) return NULL;
- table = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!table)
- {
- table = gncCloneTaxTable (table, book);
- }
- return table;
+ table = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!table)
+ {
+ table = gncCloneTaxTable (table, book);
+ }
+ return table;
}
-void
+void
gncTaxTableDestroy (GncTaxTable *table)
{
- if (!table) return;
- qof_instance_set_destroying(table, TRUE);
- qof_instance_set_dirty (&table->inst);
- gncTaxTableCommitEdit (table);
+ if (!table) return;
+ qof_instance_set_destroying(table, TRUE);
+ qof_instance_set_dirty (&table->inst);
+ gncTaxTableCommitEdit (table);
}
-static void
+static void
gncTaxTableFree (GncTaxTable *table)
{
- GList *list;
- GncTaxTable *child;
+ GList *list;
+ GncTaxTable *child;
- if (!table) return;
+ if (!table) return;
- qof_event_gen (&table->inst, QOF_EVENT_DESTROY, NULL);
- CACHE_REMOVE (table->name);
- remObj (table);
+ 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);
+ /* 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!");
+ 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 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);
+ /* 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);
+ /* 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;
+ GncTaxTableEntry *entry;
+ entry = g_new0 (GncTaxTableEntry, 1);
+ entry->amount = gnc_numeric_zero ();
+ return entry;
}
void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
{
- if (!entry) return;
- g_free (entry);
+ if (!entry) return;
+ g_free (entry);
}
-/** Makes a clone. The account is from the appriate book.
+/** 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 *
+static GncTaxTableEntry *
CloneTaxEntry (const GncTaxTableEntry*from, QofBook *book)
{
- QofInstance *acc;
- GncTaxTableEntry *entry;
- entry = g_new0 (GncTaxTableEntry, 1);
+ QofInstance *acc;
+ GncTaxTableEntry *entry;
+ entry = g_new0 (GncTaxTableEntry, 1);
- entry->type = from->type;
- entry->amount = from->amount;
+ entry->type = from->type;
+ entry->amount = from->amount;
- acc = qof_instance_lookup_twin (QOF_INSTANCE(from->account), book);
- entry->account = (Account *) acc;
- return entry;
+ acc = qof_instance_lookup_twin (QOF_INSTANCE(from->account), book);
+ entry->account = (Account *) acc;
+ return entry;
}
/* =============================================================== */
@@ -463,166 +467,169 @@
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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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);
- }
+ 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);
- }
+ 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);
- }
+ 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 */
+ if (!table || !entry) return;
+ if (entry->table == table) return; /* already mine */
- gncTaxTableBeginEdit (table);
- if (entry->table)
- gncTaxTableRemoveEntry (entry->table, entry);
+ 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);
+ 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);
+ 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);
+ if (!table) return;
+ gncTaxTableBeginEdit (table);
+ table->child = NULL;
+ gncTaxTableCommitEdit (table);
}
/* =============================================================== */
void gncTaxTableBeginEdit (GncTaxTable *table)
{
- qof_begin_edit(&table->inst);
+ qof_begin_edit(&table->inst);
}
static void gncTaxTableOnError (QofInstance *inst, QofBackendError errcode)
{
- PERR("TaxTable QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ 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);
+ if (!qof_commit_edit (QOF_INSTANCE(table))) return;
+ qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,
+ gncTaxTableOnDone, table_free);
}
@@ -631,158 +638,161 @@
GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name)
{
- GList *list = gncTaxTableGetTables (book);
+ GList *list = gncTaxTableGetTables (book);
- for ( ; list; list = list->next) {
- GncTaxTable *table = list->data;
- if (!safe_strcmp (table->name, name))
- return list->data;
- }
- return NULL;
+ 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;
+ struct _book_info *bi;
+ if (!book) return NULL;
- bi = qof_book_get_data (book, _GNC_MOD_NAME);
- return bi->tables;
+ 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;
+ if (!table) return NULL;
+ return table->name;
}
static GncTaxTableEntry *gncTaxTableEntryCopy (const GncTaxTableEntry *entry)
{
- GncTaxTableEntry *e;
- if (!entry) return NULL;
+ GncTaxTableEntry *e;
+ if (!entry) return NULL;
- e = gncTaxTableEntryCreate ();
- gncTaxTableEntrySetAccount (e, entry->account);
- gncTaxTableEntrySetType (e, entry->type);
- gncTaxTableEntrySetAmount (e, entry->amount);
+ e = gncTaxTableEntryCreate ();
+ gncTaxTableEntrySetAccount (e, entry->account);
+ gncTaxTableEntrySetType (e, entry->type);
+ gncTaxTableEntrySetAmount (e, entry->amount);
- return e;
+ return e;
}
static GncTaxTable *gncTaxTableCopy (const GncTaxTable *table)
{
- GncTaxTable *t;
- GList *list;
+ 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;
+ 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;
+ 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;
+ 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;
+ if (!table) return NULL;
+ return table->parent;
}
GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table)
{
- if (!table) return NULL;
- return table->entries;
+ if (!table) return NULL;
+ return table->entries;
}
gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
{
- if (!table) return 0;
- return table->refcount;
+ if (!table) return 0;
+ return table->refcount;
}
Timespec gncTaxTableLastModified (const GncTaxTable *table)
{
- Timespec ts = { 0 , 0 };
- if (!table) return ts;
- return table->modtime;
+ Timespec ts = { 0 , 0 };
+ if (!table) return ts;
+ return table->modtime;
}
gboolean gncTaxTableGetInvisible (const GncTaxTable *table)
{
- if (!table) return FALSE;
- return table->invisible;
+ if (!table) return FALSE;
+ return table->invisible;
}
Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry)
{
- if (!entry) return NULL;
- return entry->account;
+ if (!entry) return NULL;
+ return entry->account;
}
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry)
{
- if (!entry) return 0;
- return entry->type;
+ if (!entry) return 0;
+ return entry->type;
}
gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry)
{
- if (!entry) return gnc_numeric_zero();
- return entry->amount;
+ if (!entry) return gnc_numeric_zero();
+ return entry->amount;
}
GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry )
{
- if (!entry) return NULL;
- return entry->table;
+ if (!entry) return NULL;
+ return entry->table;
}
int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
{
- char *name_a, *name_b;
- int retval;
+ 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 (!a && !b) return 0;
+ if (!a) return -1;
+ if (!b) return 1;
- if (retval)
- return retval;
+ 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);
- return gnc_numeric_compare (a->amount, b->amount);
+ 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);
+ if (!a && !b) return 0;
+ if (!a) return -1;
+ if (!b) return 1;
+ return safe_strcmp (a->name, b->name);
}
@@ -792,116 +802,121 @@
*/
GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value)
{
- GList *li;
- GncAccountValue *res = NULL;
+ 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);
+ 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;
+ /* 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. */
+ /* Nope, didn't find it. */
- res = g_new0 (GncAccountValue, 1);
- res->account = acc;
- res->value = value;
- return g_list_prepend (list, res);
+ 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;
+ GList *li;
- for (li = l2; li; li = li->next ) {
- GncAccountValue *val = li->data;
- l1 = gncAccountValueAdd (l1, val->account, val->value);
- }
+ for (li = l2; li; li = li->next )
+ {
+ GncAccountValue *val = li->data;
+ l1 = gncAccountValueAdd (l1, val->account, val->value);
+ }
- return l1;
+ return l1;
}
/* return the total for this list */
gnc_numeric gncAccountValueTotal (GList *list)
{
- gnc_numeric total = gnc_numeric_zero ();
+ 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;
+ 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);
+ GList *node;
+ for ( node = list; node ; node = node->next)
+ g_free (node->data);
- g_list_free (list);
+ g_list_free (list);
}
/* Package-Private functions */
static void _gncTaxTableCreate (QofBook *book)
{
- struct _book_info *bi;
+ struct _book_info *bi;
- if (!book) return;
+ if (!book) return;
- bi = g_new0 (struct _book_info, 1);
- qof_book_set_data (book, _GNC_MOD_NAME, bi);
+ 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;
+ struct _book_info *bi;
- if (!book) return;
+ if (!book) return;
- bi = qof_book_get_data (book, _GNC_MOD_NAME);
+ bi = qof_book_get_data (book, _GNC_MOD_NAME);
- g_list_free (bi->tables);
- g_free (bi);
+ g_list_free (bi->tables);
+ g_free (bi);
}
-static QofObject gncTaxTableDesc =
+static QofObject gncTaxTableDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Tax Table",
- .create = (gpointer)gncTaxTableCreate,
- .book_begin = _gncTaxTableCreate,
- .book_end = _gncTaxTableDestroy,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = NULL,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Tax Table",
+ .create = (gpointer)gncTaxTableCreate,
+ .book_begin = _gncTaxTableCreate,
+ .book_end = _gncTaxTableDestroy,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = NULL,
+ .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 },
- };
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params);
- return qof_object_register (&gncTaxTableDesc);
+ return qof_object_register (&gncTaxTableDesc);
}
/* need a QOF tax table entry object */
Modified: gnucash/trunk/src/business/business-core/gncTaxTable.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncTaxTable.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncTaxTable.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -35,18 +35,18 @@
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
+Code that handles refcount, parent, child, invisible and children
is *identical* to that in ::GncBillTerm
@param QofInstance inst;
@param char * name;
@param GncTaxTableEntryList* entries;
- at param Timespec modtime;
+ at param Timespec modtime;
@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 GncTaxTable * parent; if non-null, we are an immutable child
+ at param GncTaxTable * child; if non-null, we have not changed
@param gboolean invisible;
- at param GList * children; list of children for disconnection
+ at param GList * children; list of children for disconnection
*/
typedef struct _gncTaxTable GncTaxTable;
typedef struct _gncTaxTableClass GncTaxTableClass;
@@ -90,16 +90,18 @@
* 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 */
+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 */
+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);
@@ -108,14 +110,14 @@
const char * gncTaxIncludedTypeToString (GncTaxIncluded type);
gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type);
-/** @name Create/Destroy Functions
+/** @name Create/Destroy Functions
@{ */
GncTaxTable * gncTaxTableCreate (QofBook *book);
void gncTaxTableDestroy (GncTaxTable *table);
GncTaxTableEntry * gncTaxTableEntryCreate (void);
void gncTaxTableEntryDestroy (GncTaxTableEntry *entry);
/** @} */
-/** \name Set Functions
+/** \name Set Functions
@{
*/
void gncTaxTableSetName (GncTaxTable *table, const char *name);
@@ -133,11 +135,11 @@
void gncTaxTableBeginEdit (GncTaxTable *table);
void gncTaxTableCommitEdit (GncTaxTable *table);
-/** @name Get Functions
+/** @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
+ * 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 GUID *guid);
@@ -168,9 +170,10 @@
/************************************************/
-struct _gncAccountValue {
- Account * account;
- gnc_numeric value;
+struct _gncAccountValue
+{
+ Account * account;
+ gnc_numeric value;
};
/**
Modified: gnucash/trunk/src/business/business-core/gncVendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncVendor.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -42,28 +42,28 @@
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);
+ gpointer user_data, gpointer event_data);
-struct _gncVendor
+struct _gncVendor
{
- QofInstance inst;
+ 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;
+ 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;
+ QofInstanceClass parent_class;
};
static QofLogModule log_module = GNC_MOD_BUSINESS;
@@ -76,15 +76,16 @@
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);
+ qof_instance_set_dirty(&vendor->inst);
+ qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
}
/* ============================================================== */
-enum {
+enum
+{
PROP_0,
- PROP_NAME
+ PROP_NAME
};
/* GObject Initialization */
@@ -109,43 +110,45 @@
static void
gnc_vendor_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ 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;
+ 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)
+ 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;
+ 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;
}
}
@@ -153,134 +156,135 @@
gnc_vendor_class_init (GncVendorClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_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;
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));
+ (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;
+ GncVendor *vendor;
- if (!book) return NULL;
+ 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;
+ vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
+ qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
- if (gs_address_event_handler_id == 0) {
- gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
- }
+ 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;
- qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
+ if (gs_address_event_handler_id == 0)
+ {
+ gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
+ }
- return vendor;
+ 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);
+ if (!vendor) return;
+ qof_instance_set_destroying(vendor, TRUE);
+ gncVendorCommitEdit (vendor);
}
static void gncVendorFree (GncVendor *vendor)
{
- if (!vendor) return;
+ if (!vendor) return;
- qof_event_gen (&vendor->inst, QOF_EVENT_DESTROY, NULL);
+ 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);
+ 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);
+ if (vendor->terms)
+ gncBillTermDecRef (vendor->terms);
+ if (vendor->taxtable)
+ gncTaxTableDecRef (vendor->taxtable);
- /* qof_instance_release (&vendor->inst); */
- g_object_unref (vendor);
+ /* 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;
+ GList *node;
+ GncVendor *vendor;
- if (!book) return NULL;
+ 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 = 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->terms = gncBillTermObtainTwin (from->terms, book);
- gncBillTermIncRef (vendor->terms);
+ 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->currency = gnc_commodity_obtain_twin (from->currency, book);
+ vendor->terms = gncBillTermObtainTwin (from->terms, book);
+ gncBillTermIncRef (vendor->terms);
- vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
- gncTaxTableIncRef (vendor->taxtable);
+ vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
- 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);
- }
+ vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
+ gncTaxTableIncRef (vendor->taxtable);
- qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
+ 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);
+ }
- return vendor;
+ qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
+
+ return vendor;
}
GncVendor *
gncVendorObtainTwin (GncVendor *from, QofBook *book)
{
- GncVendor *vendor;
- if (!book) return NULL;
+ GncVendor *vendor;
+ if (!book) return NULL;
- vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
- if (!vendor)
- {
- vendor = gncCloneVendor (from, book);
- }
+ vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
+ if (!vendor)
+ {
+ vendor = gncCloneVendor (from, book);
+ }
- return vendor;
+ return vendor;
}
/* ============================================================== */
@@ -298,128 +302,138 @@
void gncVendorSetID (GncVendor *vendor, const char *id)
{
- if (!vendor) return;
- if (!id) return;
- SET_STR(vendor, vendor->id, id);
- mark_vendor (vendor);
- gncVendorCommitEdit (vendor);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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;
+ 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);
+ 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;
+ GncTaxIncluded inc;
- if(!gncTaxIncludedStringToType(type_string, &inc)) { return; }
- gncVendorBeginEdit(vendor);
- vendor->taxincluded = inc;
- gncVendorCommitEdit(vendor);
+ if (!gncTaxIncludedStringToType(type_string, &inc))
+ {
+ return;
+ }
+ gncVendorBeginEdit(vendor);
+ vendor->taxincluded = inc;
+ gncVendorCommitEdit(vendor);
}
/* ============================================================== */
@@ -427,129 +441,132 @@
const char * gncVendorGetID (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->id;
+ if (!vendor) return NULL;
+ return vendor->id;
}
const char * gncVendorGetName (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->name;
+ if (!vendor) return NULL;
+ return vendor->name;
}
GncAddress * gncVendorGetAddr (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->addr;
+ if (!vendor) return NULL;
+ return vendor->addr;
}
const char * gncVendorGetNotes (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->notes;
+ if (!vendor) return NULL;
+ return vendor->notes;
}
GncBillTerm * gncVendorGetTerms (const GncVendor *vendor)
{
- if (!vendor) return 0;
- return vendor->terms;
+ if (!vendor) return 0;
+ return vendor->terms;
}
GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor)
{
- if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
- return vendor->taxincluded;
+ if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
+ return vendor->taxincluded;
}
gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->currency;
+ if (!vendor) return NULL;
+ return vendor->currency;
}
gboolean gncVendorGetActive (const GncVendor *vendor)
{
- if (!vendor) return FALSE;
- return vendor->active;
+ if (!vendor) return FALSE;
+ return vendor->active;
}
gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor)
{
- if (!vendor) return FALSE;
- return vendor->taxtable_override;
+ if (!vendor) return FALSE;
+ return vendor->taxtable_override;
}
GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor)
{
- if (!vendor) return NULL;
- return vendor->taxtable;
+ if (!vendor) return NULL;
+ return vendor->taxtable;
}
static const char*
qofVendorGetTaxIncluded(const GncVendor *vendor)
{
- return gncTaxIncludedTypeToString(vendor->taxincluded);
+ 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 (!vendor) return;
+ if (!job) return;
- if (g_list_index(vendor->jobs, job) == -1)
- vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
- (GCompareFunc)gncJobCompare);
+ 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);
+ qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
}
void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
{
- GList *node;
+ GList *node;
- if (!vendor) return;
- if (!job) return;
+ 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);
- }
+ 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);
+ qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
}
void gncVendorBeginEdit (GncVendor *vendor)
{
- qof_begin_edit(&vendor->inst);
+ qof_begin_edit(&vendor->inst);
}
static void gncVendorOnError (QofInstance *vendor, QofBackendError errcode)
{
- PERR("Vendor QofBackend Failure: %d", errcode);
- gnc_engine_signal_commit_error( 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);
+ GncVendor *vendor = (GncVendor *) inst;
+ gncAddressClearDirty (vendor->addr);
}
static void vendor_free (QofInstance *inst)
{
- GncVendor *vendor = (GncVendor *) inst;
- gncVendorFree (vendor);
+ 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);
+ if (!qof_commit_edit (QOF_INSTANCE(vendor))) return;
+ qof_commit_edit_part2 (&vendor->inst, gncVendorOnError,
+ gncVendorOnDone, vendor_free);
}
/* ============================================================== */
@@ -557,35 +574,39 @@
int gncVendorCompare (const GncVendor *a, const GncVendor *b)
{
- if (!a && !b) return 0;
- if (!a && b) return 1;
- if (a && !b) return -1;
+ if (!a && !b) return 0;
+ if (!a && b) return 1;
+ if (a && !b) return -1;
- return(strcmp(a->name, b->name));
+ return(strcmp(a->name, b->name));
}
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
{
- if (!vendor) return NULL;
+ 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);
+ if (show_all)
+ {
+ return (g_list_copy (vendor->jobs));
}
- return list;
- }
+ 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));
+ if (!vendor) return FALSE;
+ return (qof_instance_get_dirty_flag(vendor)
+ || gncAddressIsDirty (vendor->addr));
}
/**
@@ -599,78 +620,94 @@
*/
static void
listen_for_address_events(QofInstance *entity, QofEventId event_type,
- gpointer user_data, gpointer event_data)
+ gpointer user_data, gpointer event_data)
{
- GncVendor* v;
+ 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);
+ 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;
+ GncVendor *v = item;
+ if (!item) return NULL;
+ return v->name;
}
-static QofObject gncVendorDesc =
+static QofObject gncVendorDesc =
{
- .interface_version = QOF_OBJECT_VERSION,
- .e_type = _GNC_MOD_NAME,
- .type_label = "Vendor",
- .create = (gpointer)gncVendorCreate,
- .book_begin = NULL,
- .book_end = NULL,
- .is_dirty = qof_collection_is_dirty,
- .mark_clean = qof_collection_mark_clean,
- .foreach = qof_collection_foreach,
- .printable = _gncVendorPrintable,
- .version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ .interface_version = QOF_OBJECT_VERSION,
+ .e_type = _GNC_MOD_NAME,
+ .type_label = "Vendor",
+ .create = (gpointer)gncVendorCreate,
+ .book_begin = NULL,
+ .book_end = NULL,
+ .is_dirty = qof_collection_is_dirty,
+ .mark_clean = qof_collection_mark_clean,
+ .foreach = qof_collection_foreach,
+ .printable = _gncVendorPrintable,
+ .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 },
- };
+ 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; }
+ 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);
+ qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params);
- return qof_object_register (&gncVendorDesc);
+ return qof_object_register (&gncVendorDesc);
}
gint64 gncVendorNextID (QofBook *book)
{
- return qof_book_get_counter (book, _GNC_MOD_NAME);
+ return qof_book_get_counter (book, _GNC_MOD_NAME);
}
Modified: gnucash/trunk/src/business/business-core/gncVendor.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendor.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncVendor.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -24,7 +24,7 @@
/** @addtogroup Vendor
@{ */
/** @file gncVendor.h
- @brief Vendor Interface
+ @brief Vendor Interface
@author Copyright (C) 2001,2002 Derek Atkins <warlord at MIT.EDU>
*/
@@ -100,14 +100,14 @@
/** @} */
/** XXX should be renamed to RetJobList to be consistent with
- * other usage, since caller must free the copied list
+ * 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);
/** Return a pointer to the instance gncVendor that is identified
- * by the guid, and is residing in the book. Returns NULL if the
+ * 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 GUID *guid);
Modified: gnucash/trunk/src/business/business-core/gncVendorP.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncVendorP.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/gncVendorP.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -48,7 +48,7 @@
* 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
+ * it from the other Get routines, which work in fundamentally
* different ways.
*/
GncVendor * gncVendorObtainTwin (GncVendor *from, QofBook *book);
Modified: gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-address-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -49,15 +49,15 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "name", CT_STRING, ADDRESS_MAX_NAME_LEN, COL_NNUL, "name" },
- { "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_ONE },
- { "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_TWO },
- { "addr3", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_THREE },
- { "addr4", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_FOUR },
- { "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN, COL_NNUL, NULL, ADDRESS_PHONE },
- { "fax", CT_STRING, ADDRESS_MAX_FAX_LEN, COL_NNUL, NULL, ADDRESS_FAX },
- { "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN, COL_NNUL, NULL, ADDRESS_EMAIL },
- { NULL }
+ { "name", CT_STRING, ADDRESS_MAX_NAME_LEN, COL_NNUL, "name" },
+ { "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_ONE },
+ { "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_TWO },
+ { "addr3", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_THREE },
+ { "addr4", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_FOUR },
+ { "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN, COL_NNUL, NULL, ADDRESS_PHONE },
+ { "fax", CT_STRING, ADDRESS_MAX_FAX_LEN, COL_NNUL, NULL, ADDRESS_FAX },
+ { "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN, COL_NNUL, NULL, ADDRESS_EMAIL },
+ { NULL }
};
typedef void (*AddressSetterFunc)( gpointer, GncAddress* );
@@ -65,93 +65,104 @@
static void
load_address( const GncSqlBackend* be, GncSqlRow* row,
- QofSetterFunc setter, gpointer pObject,
- const GncSqlColumnTableEntry* table_row )
+ QofSetterFunc setter, gpointer pObject,
+ const GncSqlColumnTableEntry* table_row )
{
const GValue* val;
gchar* buf;
GncAddress* addr;
- AddressSetterFunc a_setter = (AddressSetterFunc)setter;
- const GncSqlColumnTableEntry* subtable;
- const gchar* s;
+ AddressSetterFunc a_setter = (AddressSetterFunc)setter;
+ const GncSqlColumnTableEntry* subtable;
+ const gchar* s;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
addr = gncAddressCreate( be->primary_book, NULL );
- for( subtable = col_table; subtable->col_name != NULL; subtable++ ) {
- buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable->col_name );
- val = gnc_sql_row_get_value_at_col_name( row, buf );
- g_free( buf );
- if( val == NULL ) {
- s = NULL;
- } else {
- s = g_value_get_string( val );
- }
- if( subtable->gobj_param_name != NULL ) {
- g_object_set( addr, subtable->gobj_param_name, s, NULL );
- } else {
- if( subtable->qof_param_name != NULL ) {
- setter = qof_class_get_parameter_setter( GNC_ID_ADDRESS, subtable->qof_param_name );
- } else {
- setter = subtable->setter;
- }
- (*setter)( addr, (const gpointer)s );
- }
+ for ( subtable = col_table; subtable->col_name != NULL; subtable++ )
+ {
+ buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable->col_name );
+ val = gnc_sql_row_get_value_at_col_name( row, buf );
+ g_free( buf );
+ if ( val == NULL )
+ {
+ s = NULL;
+ }
+ else
+ {
+ s = g_value_get_string( val );
+ }
+ if ( subtable->gobj_param_name != NULL )
+ {
+ g_object_set( addr, subtable->gobj_param_name, s, NULL );
+ }
+ else
+ {
+ if ( subtable->qof_param_name != NULL )
+ {
+ setter = qof_class_get_parameter_setter( GNC_ID_ADDRESS, subtable->qof_param_name );
+ }
+ else
+ {
+ setter = subtable->setter;
+ }
+ (*setter)( addr, (const gpointer)s );
+ }
}
(*a_setter)( pObject, addr );
}
static void
add_address_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
- GList** pList )
+ GList** pList )
{
- GncSqlColumnInfo* info;
+ GncSqlColumnInfo* info;
gchar* buf;
- const GncSqlColumnTableEntry* subtable_row;
- const gchar* type;
+ const GncSqlColumnTableEntry* subtable_row;
+ const gchar* type;
- g_return_if_fail( be != NULL );
- g_return_if_fail( table_row != NULL );
- g_return_if_fail( pList != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( table_row != NULL );
+ g_return_if_fail( pList != NULL );
- for( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ ) {
- buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable_row->col_name );
- info = g_new0( GncSqlColumnInfo, 1 );
- info->name = buf;
- info->type = BCT_STRING;
- info->size = subtable_row->size;
- info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
- info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
- info->is_unicode = TRUE;
- *pList = g_list_append( *pList, info );
- }
+ for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
+ {
+ buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable_row->col_name );
+ info = g_new0( GncSqlColumnInfo, 1 );
+ info->name = buf;
+ info->type = BCT_STRING;
+ info->size = subtable_row->size;
+ info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+ info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+ info->is_unicode = TRUE;
+ *pList = g_list_append( *pList, info );
+ }
}
static void
add_address_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
{
- gnc_sql_add_subtable_colnames_to_list( table_row, col_table, pList );
+ gnc_sql_add_subtable_colnames_to_list( table_row, col_table, pList );
}
static void
get_gvalue_address( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpointer pObject,
- const GncSqlColumnTableEntry* table_row, GValue* value )
+ const GncSqlColumnTableEntry* table_row, GValue* value )
{
AddressGetterFunc getter;
GncAddress* addr;
- g_return_if_fail( be != NULL );
- g_return_if_fail( obj_name != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
- g_return_if_fail( value != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( obj_name != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
+ g_return_if_fail( value != NULL );
memset( value, 0, sizeof( GValue ) );
- getter = (AddressGetterFunc)gnc_sql_get_getter( obj_name, table_row );
+ getter = (AddressGetterFunc)gnc_sql_get_getter( obj_name, table_row );
addr = (*getter)( pObject );
g_value_init( value, gnc_address_get_type() );
g_value_set_object( value, addr );
@@ -159,54 +170,63 @@
static void
add_gvalue_address_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
- const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
+ const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
{
GValue value;
GValue* subfield_value;
GncAddress* addr;
gchar* s;
QofAccessFunc getter;
- const GncSqlColumnTableEntry* subtable_row;
+ const GncSqlColumnTableEntry* subtable_row;
- g_return_if_fail( be != NULL );
- g_return_if_fail( obj_name != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( obj_name != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
memset( &value, 0, sizeof( GValue ) );
get_gvalue_address( be, obj_name, pObject, table_row, &value );
- if( G_VALUE_TYPE(&value) != 0 ) {
+ if ( G_VALUE_TYPE(&value) != 0 )
+ {
addr = g_value_get_object( &value );
- for( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ ) {
- subfield_value = g_new0( GValue, 1 );
- if( subtable_row->gobj_param_name != NULL ) {
- g_object_get( addr, subtable_row->gobj_param_name, &s, NULL );
- } else {
- getter = gnc_sql_get_getter( GNC_ID_ADDRESS, subtable_row );
- s = (gchar*)(*getter)( addr, NULL );
- }
- g_value_init( subfield_value, G_TYPE_STRING );
- if( s ) {
- g_value_set_string( subfield_value, s );
- } else {
- g_value_set_string( subfield_value, "NULL" );
- }
- (*pList) = g_slist_append( (*pList), subfield_value );
- }
+ for ( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ )
+ {
+ subfield_value = g_new0( GValue, 1 );
+ if ( subtable_row->gobj_param_name != NULL )
+ {
+ g_object_get( addr, subtable_row->gobj_param_name, &s, NULL );
+ }
+ else
+ {
+ getter = gnc_sql_get_getter( GNC_ID_ADDRESS, subtable_row );
+ s = (gchar*)(*getter)( addr, NULL );
+ }
+ g_value_init( subfield_value, G_TYPE_STRING );
+ if ( s )
+ {
+ g_value_set_string( subfield_value, s );
+ }
+ else
+ {
+ g_value_set_string( subfield_value, "NULL" );
+ }
+ (*pList) = g_slist_append( (*pList), subfield_value );
+ }
}
}
static GncSqlColumnTypeHandler address_handler
- = { load_address,
- add_address_col_info_to_list,
- add_address_colname_to_list,
- add_gvalue_address_to_slist };
+= { load_address,
+ add_address_col_info_to_list,
+ add_address_colname_to_list,
+ add_gvalue_address_to_slist
+ };
/* ================================================================= */
void
gnc_address_sql_initialize( void )
{
- gnc_sql_register_col_type_handler( CT_ADDRESS, &address_handler );
+ gnc_sql_register_col_type_handler( CT_ADDRESS, &address_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-bill-term-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -57,55 +57,65 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
- { "description", CT_STRING, MAX_DESCRIPTION_LEN, COL_NNUL, NULL, GNC_BILLTERM_DESC },
- { "refcount", CT_INT, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncBillTermGetRefcount, (QofSetterFunc)gncBillTermSetRefcount },
- { "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible },
- { "parent", CT_BILLTERMREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncBillTermGetParent, (QofSetterFunc)gncBillTermSetParent },
- { "child", CT_BILLTERMREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncBillTermReturnChild, (QofSetterFunc)gncBillTermSetChild },
- { "type", CT_STRING, MAX_TYPE_LEN, COL_NNUL, NULL, GNC_BILLTERM_TYPE },
- { "duedays", CT_INT, 0, 0, 0, GNC_BILLTERM_DUEDAYS },
- { "discountdays", CT_INT, 0, 0, 0, GNC_BILLTERM_DISCDAYS },
- { "discount", CT_NUMERIC, 0, 0, 0, GNC_BILLTERM_DISCOUNT },
- { "cutoff", CT_INT, 0, 0, 0, GNC_BILLTERM_CUTOFF },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
+ { "description", CT_STRING, MAX_DESCRIPTION_LEN, COL_NNUL, NULL, GNC_BILLTERM_DESC },
+ {
+ "refcount", CT_INT, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncBillTermGetRefcount, (QofSetterFunc)gncBillTermSetRefcount
+ },
+ {
+ "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible
+ },
+ {
+ "parent", CT_BILLTERMREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncBillTermGetParent, (QofSetterFunc)gncBillTermSetParent
+ },
+ {
+ "child", CT_BILLTERMREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncBillTermReturnChild, (QofSetterFunc)gncBillTermSetChild
+ },
+ { "type", CT_STRING, MAX_TYPE_LEN, COL_NNUL, NULL, GNC_BILLTERM_TYPE },
+ { "duedays", CT_INT, 0, 0, 0, GNC_BILLTERM_DUEDAYS },
+ { "discountdays", CT_INT, 0, 0, 0, GNC_BILLTERM_DISCDAYS },
+ { "discount", CT_NUMERIC, 0, 0, 0, GNC_BILLTERM_DISCOUNT },
+ { "cutoff", CT_INT, 0, 0, 0, GNC_BILLTERM_CUTOFF },
+ { NULL }
};
static void
set_invisible( gpointer data, gboolean value )
{
- GncBillTerm* term = GNC_BILLTERM(data);
+ GncBillTerm* term = GNC_BILLTERM(data);
- g_return_if_fail( term != NULL );
+ g_return_if_fail( term != NULL );
- if( value ) {
- gncBillTermMakeInvisible( term );
- }
+ if ( value )
+ {
+ gncBillTermMakeInvisible( term );
+ }
}
static GncBillTerm*
load_single_billterm( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncBillTerm* pBillTerm;
+ GncBillTerm* pBillTerm;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pBillTerm = gncBillTermLookup( be->primary_book, guid );
- if( pBillTerm == NULL ) {
+ if ( pBillTerm == NULL )
+ {
pBillTerm = gncBillTermCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_BILLTERM, pBillTerm, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pBillTerm) );
- return pBillTerm;
+ return pBillTerm;
}
static void
@@ -115,87 +125,96 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
- GncSqlRow* row;
- GList* list = NULL;
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
+ GncSqlRow* row;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncBillTerm* pBillTerm = load_single_billterm( be, row );
- if( pBillTerm != NULL ) {
- list = g_list_append( list, pBillTerm );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pBillTerm != NULL )
+ {
+ list = g_list_append( list, pBillTerm );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
/* ================================================================= */
-typedef struct {
- GncSqlBackend* be;
- gboolean is_ok;
+typedef struct
+{
+ GncSqlBackend* be;
+ gboolean is_ok;
} write_billterms_t;
static void
do_save_billterm( QofInstance* inst, gpointer p2 )
{
- write_billterms_t* data = (write_billterms_t*)p2;
+ write_billterms_t* data = (write_billterms_t*)p2;
- if( data->is_ok ) {
- data->is_ok = gnc_sql_save_billterm( data->be, inst );
- }
+ if ( data->is_ok )
+ {
+ data->is_ok = gnc_sql_save_billterm( data->be, inst );
+ }
}
static gboolean
write_billterms( GncSqlBackend* be )
{
- write_billterms_t data;
+ write_billterms_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_BILLTERM, be->primary_book, do_save_billterm, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
static void
create_billterm_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
- } else if( version == 1 ) {
- /* Upgrade 64 bit int handling */
- gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
- gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
- }
+ }
+ else if ( version == 1 )
+ {
+ /* Upgrade 64 bit int handling */
+ gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+ gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+ }
}
/* ================================================================= */
gboolean
gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
{
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_BILLTERM(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_BILLTERM(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_BILLTERM, col_table );
}
@@ -203,39 +222,47 @@
/* ================================================================= */
static void
load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row,
- QofSetterFunc setter, gpointer pObject,
- const GncSqlColumnTableEntry* table_row )
+ QofSetterFunc setter, gpointer pObject,
+ const GncSqlColumnTableEntry* table_row )
{
const GValue* val;
GUID guid;
- GncBillTerm* term = NULL;
+ GncBillTerm* term = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
- if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
+ if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+ {
string_to_guid( g_value_get_string( val ), &guid );
- term = gncBillTermLookup( be->primary_book, &guid );
- if( term != NULL ) {
- if( table_row->gobj_param_name != NULL ) {
- g_object_set( pObject, table_row->gobj_param_name, term, NULL );
- } else {
- (*setter)( pObject, (const gpointer)term );
- }
- } else {
- PWARN( "Billterm ref '%s' not found", g_value_get_string( val ) );
- }
- }
+ term = gncBillTermLookup( be->primary_book, &guid );
+ if ( term != NULL )
+ {
+ if ( table_row->gobj_param_name != NULL )
+ {
+ g_object_set( pObject, table_row->gobj_param_name, term, NULL );
+ }
+ else
+ {
+ (*setter)( pObject, (const gpointer)term );
+ }
+ }
+ else
+ {
+ PWARN( "Billterm ref '%s' not found", g_value_get_string( val ) );
+ }
+ }
}
static GncSqlColumnTypeHandler billterm_guid_handler
- = { load_billterm_guid,
- gnc_sql_add_objectref_guid_col_info_to_list,
- gnc_sql_add_colname_to_list,
- gnc_sql_add_gvalue_objectref_guid_to_slist };
+= { load_billterm_guid,
+ gnc_sql_add_objectref_guid_col_info_to_list,
+ gnc_sql_add_colname_to_list,
+ gnc_sql_add_gvalue_objectref_guid_to_slist
+ };
/* ================================================================= */
void
gnc_billterm_sql_initialize( void )
@@ -247,12 +274,12 @@
gnc_sql_save_billterm, /* commit */
load_all_billterms, /* initial_load */
create_billterm_tables, /* create_tables */
- NULL, NULL, NULL,
- write_billterms /* write */
+ NULL, NULL, NULL,
+ write_billterms /* write */
};
qof_object_register_backend( GNC_ID_BILLTERM, GNC_SQL_BACKEND, &be_data );
- gnc_sql_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
+ gnc_sql_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-customer-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -58,44 +58,51 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, CUSTOMER_ID },
- { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, CUSTOMER_NOTES },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
- { "discount", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_DISCOUNT },
- { "credit", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_CREDIT },
- { "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency },
- { "tax_override", CT_BOOLEAN, 0, COL_NNUL, NULL, CUSTOMER_TT_OVER },
- { "addr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_ADDR },
- { "shipaddr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_SHIPADDR },
- { "terms", CT_BILLTERMREF, 0, 0, NULL, CUSTOMER_TERMS },
- { "tax_included", CT_INT, 0, 0, NULL, NULL,
- (QofAccessFunc)gncCustomerGetTaxIncluded, (QofSetterFunc)gncCustomerSetTaxIncluded },
- { "taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, CUSTOMER_ID },
+ { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, CUSTOMER_NOTES },
+ { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+ { "discount", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_DISCOUNT },
+ { "credit", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_CREDIT },
+ {
+ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency
+ },
+ { "tax_override", CT_BOOLEAN, 0, COL_NNUL, NULL, CUSTOMER_TT_OVER },
+ { "addr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_ADDR },
+ { "shipaddr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_SHIPADDR },
+ { "terms", CT_BILLTERMREF, 0, 0, NULL, CUSTOMER_TERMS },
+ {
+ "tax_included", CT_INT, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncCustomerGetTaxIncluded, (QofSetterFunc)gncCustomerSetTaxIncluded
+ },
+ {
+ "taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable
+ },
+ { NULL }
};
static GncCustomer*
load_single_customer( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncCustomer* pCustomer;
+ GncCustomer* pCustomer;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pCustomer = gncCustomerLookup( be->primary_book, guid );
- if( pCustomer == NULL ) {
+ if ( pCustomer == NULL )
+ {
pCustomer = gncCustomerCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_CUSTOMER, pCustomer, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
- return pCustomer;
+ return pCustomer;
}
static void
@@ -105,30 +112,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
- GList* list = NULL;
- GncSqlRow* row;
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
+ GList* list = NULL;
+ GncSqlRow* row;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncCustomer* pCustomer = load_single_customer( be, row );
- if( pCustomer != NULL ) {
- list = g_list_append( list, pCustomer );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pCustomer != NULL )
+ {
+ list = g_list_append( list, pCustomer );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -136,35 +147,39 @@
static void
create_customer_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
- } else if( version == 1 ) {
- /* Upgrade 64 bit int handling */
- gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
- gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
}
+ else if ( version == 1 )
+ {
+ /* Upgrade 64 bit int handling */
+ gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+ gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+ }
}
/* ================================================================= */
static gboolean
save_customer( GncSqlBackend* be, QofInstance* inst )
{
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_CUSTOMER(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_CUSTOMER(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_CUSTOMER, col_table );
}
/* ================================================================= */
-typedef struct {
- GncSqlBackend* be;
- gboolean is_ok;
+typedef struct
+{
+ GncSqlBackend* be;
+ gboolean is_ok;
} write_customers_t;
static gboolean
@@ -172,13 +187,14 @@
{
const char *id;
- g_return_val_if_fail( customer != NULL, FALSE );
+ g_return_val_if_fail( customer != NULL, FALSE );
/* Make sure this is a valid customer before we save it -- should have an ID */
id = gncCustomerGetID( customer );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -186,28 +202,29 @@
static void
write_single_customer( QofInstance *term_p, gpointer data_p )
{
- write_customers_t* data = (write_customers_t*)data_p;
+ write_customers_t* data = (write_customers_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( customer_should_be_saved( GNC_CUSTOMER(term_p) ) && data->is_ok ) {
- data->is_ok = save_customer( data->be, term_p );
- }
+ if ( customer_should_be_saved( GNC_CUSTOMER(term_p) ) && data->is_ok )
+ {
+ data->is_ok = save_customer( data->be, term_p );
+ }
}
static gboolean
write_customers( GncSqlBackend* be )
{
- write_customers_t data;
+ write_customers_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_CUSTOMER, be->primary_book, write_single_customer, (gpointer)&data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
@@ -221,8 +238,8 @@
save_customer, /* commit */
load_all_customers, /* initial_load */
create_customer_tables, /* create_tables */
- NULL, NULL, NULL,
- write_customers /* write */
+ NULL, NULL, NULL,
+ write_customers /* write */
};
qof_object_register_backend( GNC_ID_CUSTOMER, GNC_SQL_BACKEND, &be_data );
Modified: gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-employee-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -58,18 +58,20 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "username", CT_STRING, MAX_USERNAME_LEN, COL_NNUL, "username" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, EMPLOYEE_ID },
- { "language", CT_STRING, MAX_LANGUAGE_LEN, COL_NNUL, NULL, EMPLOYEE_LANGUAGE },
- { "acl", CT_STRING, MAX_ACL_LEN, COL_NNUL, NULL, EMPLOYEE_ACL },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
- { "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency },
- { "ccard_guid", CT_ACCOUNTREF, 0, 0, NULL, EMPLOYEE_CC },
- { "workday", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_WORKDAY },
- { "rate", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_RATE },
- { "addr", CT_ADDRESS, 0, 0, NULL, EMPLOYEE_ADDR },
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "username", CT_STRING, MAX_USERNAME_LEN, COL_NNUL, "username" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, EMPLOYEE_ID },
+ { "language", CT_STRING, MAX_LANGUAGE_LEN, COL_NNUL, NULL, EMPLOYEE_LANGUAGE },
+ { "acl", CT_STRING, MAX_ACL_LEN, COL_NNUL, NULL, EMPLOYEE_ACL },
+ { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+ {
+ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency
+ },
+ { "ccard_guid", CT_ACCOUNTREF, 0, 0, NULL, EMPLOYEE_CC },
+ { "workday", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_WORKDAY },
+ { "rate", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_RATE },
+ { "addr", CT_ADDRESS, 0, 0, NULL, EMPLOYEE_ADDR },
{ NULL }
};
@@ -77,20 +79,21 @@
load_single_employee( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncEmployee* pEmployee;
+ GncEmployee* pEmployee;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pEmployee = gncEmployeeLookup( be->primary_book, guid );
- if( pEmployee == NULL ) {
+ if ( pEmployee == NULL )
+ {
pEmployee = gncEmployeeCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_EMPLOYEE, pEmployee, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pEmployee) );
- return pEmployee;
+ return pEmployee;
}
static void
@@ -101,31 +104,35 @@
QofBook* pBook;
gnc_commodity_table* pTable;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
pTable = gnc_commodity_table_get_table( pBook );
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncEmployee* pEmployee = load_single_employee( be, row );
- if( pEmployee != NULL ) {
- list = g_list_append( list, pEmployee );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pEmployee != NULL )
+ {
+ list = g_list_append( list, pEmployee );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -133,18 +140,21 @@
static void
create_employee_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
- } else if( version == 1 ) {
- /* Upgrade 64 bit int handling */
- gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
- gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
}
+ else if ( version == 1 )
+ {
+ /* Upgrade 64 bit int handling */
+ gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+ gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+ }
}
/* ================================================================= */
@@ -153,44 +163,55 @@
{
GncEmployee* emp;
const GUID* guid;
- gint op;
- gboolean is_infant;
- gboolean is_ok = TRUE;
+ gint op;
+ gboolean is_infant;
+ gboolean is_ok = TRUE;
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_EMPLOYEE(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_EMPLOYEE(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
emp = GNC_EMPLOYEE(inst);
- is_infant = qof_instance_get_infant( inst );
- if( qof_instance_get_destroying( inst ) ) {
- op = OP_DB_DELETE;
- } else if( be->is_pristine_db || is_infant ) {
- op = OP_DB_INSERT;
- } else {
- op = OP_DB_UPDATE;
- }
- if( op != OP_DB_DELETE ) {
- // Ensure the commodity is in the db
- is_ok = gnc_sql_save_commodity( be, gncEmployeeGetCurrency( emp ) );
- }
+ is_infant = qof_instance_get_infant( inst );
+ if ( qof_instance_get_destroying( inst ) )
+ {
+ op = OP_DB_DELETE;
+ }
+ else if ( be->is_pristine_db || is_infant )
+ {
+ op = OP_DB_INSERT;
+ }
+ else
+ {
+ op = OP_DB_UPDATE;
+ }
+ if ( op != OP_DB_DELETE )
+ {
+ // Ensure the commodity is in the db
+ is_ok = gnc_sql_save_commodity( be, gncEmployeeGetCurrency( emp ) );
+ }
- if( is_ok ) {
- is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table );
- }
+ if ( is_ok )
+ {
+ is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table );
+ }
- if( is_ok ) {
- // Now, commit or delete any slots
- guid = qof_instance_get_guid( inst );
- if( !qof_instance_get_destroying(inst) ) {
- is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
- } else {
- is_ok = gnc_sql_slots_delete( be, guid );
- }
- }
+ if ( is_ok )
+ {
+ // Now, commit or delete any slots
+ guid = qof_instance_get_guid( inst );
+ if ( !qof_instance_get_destroying(inst) )
+ {
+ is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+ }
+ else
+ {
+ is_ok = gnc_sql_slots_delete( be, guid );
+ }
+ }
- return is_ok;
+ return is_ok;
}
/* ================================================================= */
@@ -199,13 +220,14 @@
{
const char *id;
- g_return_val_if_fail( employee != NULL, FALSE );
+ g_return_val_if_fail( employee != NULL, FALSE );
/* make sure this is a valid employee before we save it -- should have an ID */
id = gncEmployeeGetID( employee );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -213,29 +235,30 @@
static void
write_single_employee( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
+ write_objects_t* s = (write_objects_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_EMPLOYEE(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_EMPLOYEE(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( s->is_ok && employee_should_be_saved( GNC_EMPLOYEE(term_p) ) ) {
- s->is_ok = save_employee( s->be, term_p );
- }
+ if ( s->is_ok && employee_should_be_saved( GNC_EMPLOYEE(term_p) ) )
+ {
+ s->is_ok = save_employee( s->be, term_p );
+ }
}
static gboolean
write_employees( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_EMPLOYEE, be->primary_book, write_single_employee, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
@@ -249,8 +272,8 @@
save_employee, /* commit */
load_all_employees, /* initial_load */
create_employee_tables, /* create_tables */
- NULL, NULL, NULL,
- write_employees /* write */
+ NULL, NULL, NULL,
+ write_employees /* write */
};
qof_object_register_backend( GNC_ID_EMPLOYEE, GNC_SQL_BACKEND, &be_data );
Modified: gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-entry-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -65,94 +65,109 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "date", CT_TIMESPEC, 0, COL_NNUL, NULL, ENTRY_DATE },
- { "date_entered", CT_TIMESPEC, 0, 0, NULL, ENTRY_DATE_ENTERED },
- { "description", CT_STRING, MAX_DESCRIPTION_LEN, 0, "description" },
- { "action", CT_STRING, MAX_ACTION_LEN, 0, NULL, ENTRY_ACTION },
- { "notes", CT_STRING, MAX_NOTES_LEN, 0, NULL, ENTRY_NOTES },
- { "quantity", CT_NUMERIC, 0, 0, NULL, ENTRY_QTY },
- { "i_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_IACCT },
- { "i_price", CT_NUMERIC, 0, 0, NULL, ENTRY_IPRICE },
- { "i_discount", CT_NUMERIC, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetInvDiscount, (QofSetterFunc)gncEntrySetInvDiscount },
- { "invoice", CT_INVOICEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetInvoice, (QofSetterFunc)entry_set_invoice },
- { "i_disc_type", CT_STRING, MAX_DISCTYPE_LEN, 0, NULL, ENTRY_INV_DISC_TYPE },
- { "i_disc_how", CT_STRING, MAX_DISCHOW_LEN, 0, NULL, ENTRY_INV_DISC_HOW },
- { "i_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAXABLE },
- { "i_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAX_INC },
- { "i_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetInvTaxTable, (QofSetterFunc)gncEntrySetInvTaxTable },
- { "b_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_BACCT },
- { "b_price", CT_NUMERIC, 0, 0, NULL, ENTRY_BPRICE },
- { "bill", CT_INVOICEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetBill, (QofSetterFunc)entry_set_bill },
- { "b_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAXABLE },
- { "b_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAX_INC },
- { "b_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetBillTaxTable, (QofSetterFunc)gncEntrySetBillTaxTable },
- { "b_paytype", CT_INT, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetBillPayment, (QofSetterFunc)gncEntrySetBillPayment },
- { "billable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILLABLE },
- { "billto", CT_OWNERREF, 0, 0, NULL, ENTRY_BILLTO },
- { "order_guid", CT_ORDERREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "date", CT_TIMESPEC, 0, COL_NNUL, NULL, ENTRY_DATE },
+ { "date_entered", CT_TIMESPEC, 0, 0, NULL, ENTRY_DATE_ENTERED },
+ { "description", CT_STRING, MAX_DESCRIPTION_LEN, 0, "description" },
+ { "action", CT_STRING, MAX_ACTION_LEN, 0, NULL, ENTRY_ACTION },
+ { "notes", CT_STRING, MAX_NOTES_LEN, 0, NULL, ENTRY_NOTES },
+ { "quantity", CT_NUMERIC, 0, 0, NULL, ENTRY_QTY },
+ { "i_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_IACCT },
+ { "i_price", CT_NUMERIC, 0, 0, NULL, ENTRY_IPRICE },
+ {
+ "i_discount", CT_NUMERIC, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetInvDiscount, (QofSetterFunc)gncEntrySetInvDiscount
+ },
+ {
+ "invoice", CT_INVOICEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetInvoice, (QofSetterFunc)entry_set_invoice
+ },
+ { "i_disc_type", CT_STRING, MAX_DISCTYPE_LEN, 0, NULL, ENTRY_INV_DISC_TYPE },
+ { "i_disc_how", CT_STRING, MAX_DISCHOW_LEN, 0, NULL, ENTRY_INV_DISC_HOW },
+ { "i_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAXABLE },
+ { "i_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAX_INC },
+ {
+ "i_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetInvTaxTable, (QofSetterFunc)gncEntrySetInvTaxTable
+ },
+ { "b_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_BACCT },
+ { "b_price", CT_NUMERIC, 0, 0, NULL, ENTRY_BPRICE },
+ {
+ "bill", CT_INVOICEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetBill, (QofSetterFunc)entry_set_bill
+ },
+ { "b_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAXABLE },
+ { "b_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAX_INC },
+ {
+ "b_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetBillTaxTable, (QofSetterFunc)gncEntrySetBillTaxTable
+ },
+ {
+ "b_paytype", CT_INT, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetBillPayment, (QofSetterFunc)gncEntrySetBillPayment
+ },
+ { "billable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILLABLE },
+ { "billto", CT_OWNERREF, 0, 0, NULL, ENTRY_BILLTO },
+ {
+ "order_guid", CT_ORDERREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder
+ },
+ { NULL }
};
static void
entry_set_invoice( gpointer pObject, gpointer val )
{
- GncEntry* entry;
- GncInvoice* invoice;
+ GncEntry* entry;
+ GncInvoice* invoice;
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( GNC_IS_ENTRY(pObject) );
- g_return_if_fail( val != NULL );
- g_return_if_fail( GNC_IS_INVOICE(val) );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( GNC_IS_ENTRY(pObject) );
+ g_return_if_fail( val != NULL );
+ g_return_if_fail( GNC_IS_INVOICE(val) );
- entry = GNC_ENTRY(pObject);
- invoice = GNC_INVOICE(val);
+ entry = GNC_ENTRY(pObject);
+ invoice = GNC_INVOICE(val);
- gncInvoiceAddEntry( invoice, entry );
+ gncInvoiceAddEntry( invoice, entry );
}
static void
entry_set_bill( gpointer pObject, gpointer val )
{
- GncEntry* entry;
- GncInvoice* bill;
+ GncEntry* entry;
+ GncInvoice* bill;
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( GNC_IS_ENTRY(pObject) );
- g_return_if_fail( val != NULL );
- g_return_if_fail( GNC_IS_INVOICE(val) );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( GNC_IS_ENTRY(pObject) );
+ g_return_if_fail( val != NULL );
+ g_return_if_fail( GNC_IS_INVOICE(val) );
- entry = GNC_ENTRY(pObject);
- bill = GNC_INVOICE(val);
+ entry = GNC_ENTRY(pObject);
+ bill = GNC_INVOICE(val);
- gncBillAddEntry( bill, entry );
+ gncBillAddEntry( bill, entry );
}
static GncEntry*
load_single_entry( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncEntry* pEntry;
+ GncEntry* pEntry;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pEntry = gncEntryLookup( be->primary_book, guid );
- if( pEntry == NULL ) {
+ if ( pEntry == NULL )
+ {
pEntry = gncEntryCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_ENTRY, pEntry, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pEntry) );
- return pEntry;
+ return pEntry;
}
static void
@@ -162,30 +177,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncEntry* pEntry = load_single_entry( be, row );
- if( pEntry != NULL ) {
- list = g_list_append( list, pEntry );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pEntry != NULL )
+ {
+ list = g_list_append( list, pEntry );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -193,30 +212,33 @@
static void
create_entry_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
- } else if( version < TABLE_VERSION ) {
- /* Upgrade:
- 1->2: 64 bit int handling
- 2->3: "entered" -> "date_entered", and it can be NULL
- */
- gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
- gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
}
+ else if ( version < TABLE_VERSION )
+ {
+ /* Upgrade:
+ 1->2: 64 bit int handling
+ 2->3: "entered" -> "date_entered", and it can be NULL
+ */
+ gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+ gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+ }
}
/* ================================================================= */
static gboolean
save_entry( GncSqlBackend* be, QofInstance* inst )
{
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_ENTRY(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_ENTRY(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ENTRY, col_table );
}
@@ -225,32 +247,33 @@
static void
write_single_entry( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
- GncEntry* entry = GNC_ENTRY(term_p);
+ write_objects_t* s = (write_objects_t*)data_p;
+ GncEntry* entry = GNC_ENTRY(term_p);
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_ENTRY(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_ENTRY(term_p) );
+ g_return_if_fail( data_p != NULL );
- /* Only save if attached */
- if( s->is_ok && (gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
- gncEntryGetBill( entry ) != NULL) ) {
- s->is_ok = save_entry( s->be, term_p );
- }
+ /* Only save if attached */
+ if ( s->is_ok && (gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
+ gncEntryGetBill( entry ) != NULL) )
+ {
+ s->is_ok = save_entry( s->be, term_p );
+ }
}
static gboolean
write_entries( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_ENTRY, be->primary_book, write_single_entry, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
@@ -264,8 +287,8 @@
save_entry, /* commit */
load_all_entries, /* initial_load */
create_entry_tables, /* create_tables */
- NULL, NULL, NULL,
- write_entries /* write */
+ NULL, NULL, NULL,
+ write_entries /* write */
};
qof_object_register_backend( GNC_ID_ENTRY, GNC_SQL_BACKEND, &be_data );
Modified: gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-invoice-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -59,47 +59,58 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, INVOICE_ID },
- { "date_opened", CT_TIMESPEC, 0, 0, NULL, INVOICE_OPENED },
- { "date_posted", CT_TIMESPEC, 0, 0, NULL, INVOICE_POSTED },
- { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, "notes" },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
- { "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency },
- { "owner", CT_OWNERREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)gncInvoiceSetOwner },
- { "terms", CT_BILLTERMREF, 0, 0, NULL, INVOICE_TERMS },
- { "billing_id", CT_STRING, MAX_BILLING_ID_LEN, 0, NULL, INVOICE_BILLINGID },
- { "post_txn", CT_TXREF, 0, 0, NULL, INVOICE_POST_TXN },
- { "post_lot", CT_LOTREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncInvoiceGetPostedLot, (QofSetterFunc)gncInvoiceSetPostedLot },
- { "post_acc", CT_ACCOUNTREF, 0, 0, NULL, INVOICE_ACC },
- { "billto", CT_OWNERREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncInvoiceGetBillTo, (QofSetterFunc)gncInvoiceSetBillTo },
- { "charge_amt", CT_NUMERIC, 0, 0, NULL, NULL,
- (QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, INVOICE_ID },
+ { "date_opened", CT_TIMESPEC, 0, 0, NULL, INVOICE_OPENED },
+ { "date_posted", CT_TIMESPEC, 0, 0, NULL, INVOICE_POSTED },
+ { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, "notes" },
+ { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+ {
+ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency
+ },
+ {
+ "owner", CT_OWNERREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)gncInvoiceSetOwner
+ },
+ { "terms", CT_BILLTERMREF, 0, 0, NULL, INVOICE_TERMS },
+ { "billing_id", CT_STRING, MAX_BILLING_ID_LEN, 0, NULL, INVOICE_BILLINGID },
+ { "post_txn", CT_TXREF, 0, 0, NULL, INVOICE_POST_TXN },
+ {
+ "post_lot", CT_LOTREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncInvoiceGetPostedLot, (QofSetterFunc)gncInvoiceSetPostedLot
+ },
+ { "post_acc", CT_ACCOUNTREF, 0, 0, NULL, INVOICE_ACC },
+ {
+ "billto", CT_OWNERREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncInvoiceGetBillTo, (QofSetterFunc)gncInvoiceSetBillTo
+ },
+ {
+ "charge_amt", CT_NUMERIC, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount
+ },
+ { NULL }
};
static GncInvoice*
load_single_invoice( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncInvoice* pInvoice;
+ GncInvoice* pInvoice;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pInvoice = gncInvoiceLookup( be->primary_book, guid );
- if( pInvoice == NULL ) {
+ if ( pInvoice == NULL )
+ {
pInvoice = gncInvoiceCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_INVOICE, pInvoice, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pInvoice) );
- return pInvoice;
+ return pInvoice;
}
static void
@@ -109,30 +120,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
- GncInvoice* pInvoice = load_single_invoice( be, row );
- if( pInvoice != NULL ) {
- list = g_list_append( list, pInvoice );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
+ GncInvoice* pInvoice = load_single_invoice( be, row );
+ if ( pInvoice != NULL )
+ {
+ list = g_list_append( list, pInvoice );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -140,21 +155,24 @@
static void
create_invoice_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
- } else if( version < TABLE_VERSION ) {
- /* Upgrade:
- 1->2: 64 bit int handling
- 2->3: invoice open date can be NULL
- */
- gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
- gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
}
+ else if ( version < TABLE_VERSION )
+ {
+ /* Upgrade:
+ 1->2: 64 bit int handling
+ 2->3: invoice open date can be NULL
+ */
+ gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
+ gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
+ }
}
/* ================================================================= */
@@ -162,45 +180,56 @@
save_invoice( GncSqlBackend* be, QofInstance* inst )
{
const GUID* guid;
- GncInvoice* invoice;
- gint op;
- gboolean is_infant;
- gboolean is_ok = TRUE;
+ GncInvoice* invoice;
+ gint op;
+ gboolean is_infant;
+ gboolean is_ok = TRUE;
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_INVOICE(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_INVOICE(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- invoice = GNC_INVOICE(inst);
+ invoice = GNC_INVOICE(inst);
- is_infant = qof_instance_get_infant( inst );
- if( qof_instance_get_destroying( inst ) ) {
- op = OP_DB_DELETE;
- } else if( be->is_pristine_db || is_infant ) {
- op = OP_DB_INSERT;
- } else {
- op = OP_DB_UPDATE;
- }
- if( op != OP_DB_DELETE ) {
- // Ensure the commodity is in the db
- is_ok = gnc_sql_save_commodity( be, gncInvoiceGetCurrency( invoice ) );
- }
+ is_infant = qof_instance_get_infant( inst );
+ if ( qof_instance_get_destroying( inst ) )
+ {
+ op = OP_DB_DELETE;
+ }
+ else if ( be->is_pristine_db || is_infant )
+ {
+ op = OP_DB_INSERT;
+ }
+ else
+ {
+ op = OP_DB_UPDATE;
+ }
+ if ( op != OP_DB_DELETE )
+ {
+ // Ensure the commodity is in the db
+ is_ok = gnc_sql_save_commodity( be, gncInvoiceGetCurrency( invoice ) );
+ }
- if( is_ok ) {
- is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table );
- }
+ if ( is_ok )
+ {
+ is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table );
+ }
- if( is_ok ) {
- // Now, commit or delete any slots
- guid = qof_instance_get_guid( inst );
- if( !qof_instance_get_destroying(inst) ) {
- is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
- } else {
- is_ok = gnc_sql_slots_delete( be, guid );
- }
- }
+ if ( is_ok )
+ {
+ // Now, commit or delete any slots
+ guid = qof_instance_get_guid( inst );
+ if ( !qof_instance_get_destroying(inst) )
+ {
+ is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+ }
+ else
+ {
+ is_ok = gnc_sql_slots_delete( be, guid );
+ }
+ }
- return is_ok;
+ return is_ok;
}
/* ================================================================= */
@@ -209,13 +238,14 @@
{
const char *id;
- g_return_val_if_fail( invoice != NULL, FALSE );
+ g_return_val_if_fail( invoice != NULL, FALSE );
/* make sure this is a valid invoice before we save it -- should have an ID */
id = gncInvoiceGetID( invoice );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -223,67 +253,76 @@
static void
write_single_invoice( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
+ write_objects_t* s = (write_objects_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_INVOICE(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_INVOICE(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( s->is_ok && invoice_should_be_saved( GNC_INVOICE(term_p) ) ) {
- s->is_ok = save_invoice( s->be, term_p );
- }
+ if ( s->is_ok && invoice_should_be_saved( GNC_INVOICE(term_p) ) )
+ {
+ s->is_ok = save_invoice( s->be, term_p );
+ }
}
static gboolean
write_invoices( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_INVOICE, be->primary_book, write_single_invoice, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
static void
load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row,
- QofSetterFunc setter, gpointer pObject,
- const GncSqlColumnTableEntry* table_row )
+ QofSetterFunc setter, gpointer pObject,
+ const GncSqlColumnTableEntry* table_row )
{
const GValue* val;
GUID guid;
- GncInvoice* invoice = NULL;
+ GncInvoice* invoice = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
- if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
+ if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+ {
string_to_guid( g_value_get_string( val ), &guid );
- invoice = gncInvoiceLookup( be->primary_book, &guid );
- if( invoice != NULL ) {
- if( table_row->gobj_param_name != NULL ) {
- g_object_set( pObject, table_row->gobj_param_name, invoice, NULL );
- } else {
- (*setter)( pObject, (const gpointer)invoice );
- }
- } else {
- PWARN( "Invoice ref '%s' not found", g_value_get_string( val ) );
- }
- }
+ invoice = gncInvoiceLookup( be->primary_book, &guid );
+ if ( invoice != NULL )
+ {
+ if ( table_row->gobj_param_name != NULL )
+ {
+ g_object_set( pObject, table_row->gobj_param_name, invoice, NULL );
+ }
+ else
+ {
+ (*setter)( pObject, (const gpointer)invoice );
+ }
+ }
+ else
+ {
+ PWARN( "Invoice ref '%s' not found", g_value_get_string( val ) );
+ }
+ }
}
static GncSqlColumnTypeHandler invoice_guid_handler
- = { load_invoice_guid,
- gnc_sql_add_objectref_guid_col_info_to_list,
- gnc_sql_add_colname_to_list,
- gnc_sql_add_gvalue_objectref_guid_to_slist };
+= { load_invoice_guid,
+ gnc_sql_add_objectref_guid_col_info_to_list,
+ gnc_sql_add_colname_to_list,
+ gnc_sql_add_gvalue_objectref_guid_to_slist
+ };
/* ================================================================= */
void
gnc_invoice_sql_initialize( void )
@@ -295,12 +334,12 @@
save_invoice, /* commit */
load_all_invoices, /* initial_load */
create_invoice_tables, /* create_tables */
- NULL, NULL, NULL,
- write_invoices /* write */
+ NULL, NULL, NULL,
+ write_invoices /* write */
};
qof_object_register_backend( GNC_ID_INVOICE, GNC_SQL_BACKEND, &be_data );
- gnc_sql_register_col_type_handler( CT_INVOICEREF, &invoice_guid_handler );
+ gnc_sql_register_col_type_handler( CT_INVOICEREF, &invoice_guid_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-job-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -54,35 +54,40 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, JOB_ID },
- { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
- { "reference", CT_STRING, MAX_REFERENCE_LEN, COL_NNUL, NULL, JOB_REFERENCE },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive },
- { "owner", CT_OWNERREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, JOB_ID },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
+ { "reference", CT_STRING, MAX_REFERENCE_LEN, COL_NNUL, NULL, JOB_REFERENCE },
+ {
+ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive
+ },
+ {
+ "owner", CT_OWNERREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner
+ },
+ { NULL }
};
static GncJob*
load_single_job( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncJob* pJob;
+ GncJob* pJob;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pJob = gncJobLookup( be->primary_book, guid );
- if( pJob == NULL ) {
+ if ( pJob == NULL )
+ {
pJob = gncJobCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_JOB, pJob, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pJob) );
- return pJob;
+ return pJob;
}
static void
@@ -92,30 +97,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncJob* pJob = load_single_job( be, row );
- if( pJob != NULL ) {
- list = g_list_append( list, pJob );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pJob != NULL )
+ {
+ list = g_list_append( list, pJob );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -123,12 +132,13 @@
static void
create_job_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
}
}
@@ -137,9 +147,9 @@
static gboolean
save_job( GncSqlBackend* be, QofInstance* inst )
{
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_JOB(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_JOB(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_JOB, col_table );
}
@@ -150,13 +160,14 @@
{
const char *id;
- g_return_val_if_fail( job != NULL, FALSE );
+ g_return_val_if_fail( job != NULL, FALSE );
/* make sure this is a valid job before we save it -- should have an ID */
id = gncJobGetID( job );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -164,29 +175,30 @@
static void
write_single_job( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
+ write_objects_t* s = (write_objects_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_JOB(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_JOB(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( s->is_ok && job_should_be_saved( GNC_JOB(term_p) ) ) {
- s->is_ok = save_job( s->be, term_p );
- }
+ if ( s->is_ok && job_should_be_saved( GNC_JOB(term_p) ) )
+ {
+ s->is_ok = save_job( s->be, term_p );
+ }
}
static gboolean
write_jobs( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_JOB, be->primary_book, write_single_job, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
@@ -200,8 +212,8 @@
save_job, /* commit */
load_all_jobs, /* initial_load */
create_job_tables, /* create_tables */
- NULL, NULL, NULL,
- write_jobs /* write */
+ NULL, NULL, NULL,
+ write_jobs /* write */
};
qof_object_register_backend( GNC_ID_JOB, GNC_SQL_BACKEND, &be_data );
Modified: gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-order-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -55,35 +55,36 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, ORDER_ID },
- { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, "notes" },
- { "reference", CT_STRING, MAX_REFERENCE_LEN, COL_NNUL, NULL, ORDER_REFERENCE },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
- { "date_opened", CT_TIMESPEC, 0, COL_NNUL, NULL, ORDER_OPENED },
- { "date_closed", CT_TIMESPEC, 0, COL_NNUL, NULL, ORDER_CLOSED },
- { "owner", CT_OWNERREF, 0, COL_NNUL, NULL, ORDER_OWNER },
- { NULL },
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, ORDER_ID },
+ { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, "notes" },
+ { "reference", CT_STRING, MAX_REFERENCE_LEN, COL_NNUL, NULL, ORDER_REFERENCE },
+ { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+ { "date_opened", CT_TIMESPEC, 0, COL_NNUL, NULL, ORDER_OPENED },
+ { "date_closed", CT_TIMESPEC, 0, COL_NNUL, NULL, ORDER_CLOSED },
+ { "owner", CT_OWNERREF, 0, COL_NNUL, NULL, ORDER_OWNER },
+ { NULL },
};
static GncOrder*
load_single_order( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncOrder* pOrder;
+ GncOrder* pOrder;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pOrder = gncOrderLookup( be->primary_book, guid );
- if( pOrder == NULL ) {
+ if ( pOrder == NULL )
+ {
pOrder = gncOrderCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_ORDER, pOrder, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pOrder) );
- return pOrder;
+ return pOrder;
}
static void
@@ -93,30 +94,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncOrder* pOrder = load_single_order( be, row );
- if( pOrder != NULL ) {
- list = g_list_append( list, pOrder );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pOrder != NULL )
+ {
+ list = g_list_append( list, pOrder );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -124,12 +129,13 @@
static void
create_order_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
}
}
@@ -138,9 +144,9 @@
static gboolean
save_order( GncSqlBackend* be, QofInstance* inst )
{
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_ORDER(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_ORDER(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ORDER, col_table );
}
@@ -151,13 +157,14 @@
{
const char *id;
- g_return_val_if_fail( order != NULL, FALSE );
+ g_return_val_if_fail( order != NULL, FALSE );
/* make sure this is a valid order before we save it -- should have an ID */
id = gncOrderGetID( order );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -165,67 +172,76 @@
static void
write_single_order( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
+ write_objects_t* s = (write_objects_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_ORDER(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_ORDER(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( s->is_ok && order_should_be_saved( GNC_ORDER(term_p) ) ) {
- s->is_ok = save_order( s->be, term_p );
- }
+ if ( s->is_ok && order_should_be_saved( GNC_ORDER(term_p) ) )
+ {
+ s->is_ok = save_order( s->be, term_p );
+ }
}
static gboolean
write_orders( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_ORDER, be->primary_book, write_single_order, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
static void
load_order_guid( const GncSqlBackend* be, GncSqlRow* row,
- QofSetterFunc setter, gpointer pObject,
- const GncSqlColumnTableEntry* table_row )
+ QofSetterFunc setter, gpointer pObject,
+ const GncSqlColumnTableEntry* table_row )
{
const GValue* val;
GUID guid;
- GncOrder* order = NULL;
+ GncOrder* order = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
- if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
+ if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+ {
string_to_guid( g_value_get_string( val ), &guid );
- order = gncOrderLookup( be->primary_book, &guid );
- if( order != NULL ) {
- if( table_row->gobj_param_name != NULL ) {
- g_object_set( pObject, table_row->gobj_param_name, order, NULL );
- } else {
- (*setter)( pObject, (const gpointer)order );
- }
- } else {
- PWARN( "Order ref '%s' not found", g_value_get_string( val ) );
- }
- }
+ order = gncOrderLookup( be->primary_book, &guid );
+ if ( order != NULL )
+ {
+ if ( table_row->gobj_param_name != NULL )
+ {
+ g_object_set( pObject, table_row->gobj_param_name, order, NULL );
+ }
+ else
+ {
+ (*setter)( pObject, (const gpointer)order );
+ }
+ }
+ else
+ {
+ PWARN( "Order ref '%s' not found", g_value_get_string( val ) );
+ }
+ }
}
static GncSqlColumnTypeHandler order_guid_handler
- = { load_order_guid,
- gnc_sql_add_objectref_guid_col_info_to_list,
- gnc_sql_add_colname_to_list,
- gnc_sql_add_gvalue_objectref_guid_to_slist };
+= { load_order_guid,
+ gnc_sql_add_objectref_guid_col_info_to_list,
+ gnc_sql_add_colname_to_list,
+ gnc_sql_add_gvalue_objectref_guid_to_slist
+ };
/* ================================================================= */
void
gnc_order_sql_initialize( void )
@@ -237,12 +253,12 @@
save_order, /* commit */
load_all_orders, /* initial_load */
create_order_tables, /* create_tables */
- NULL, NULL, NULL,
- write_orders /* write */
+ NULL, NULL, NULL,
+ write_orders /* write */
};
qof_object_register_backend( GNC_ID_ORDER, GNC_SQL_BACKEND, &be_data );
- gnc_sql_register_col_type_handler( CT_ORDERREF, &order_guid_handler );
+ gnc_sql_register_col_type_handler( CT_ORDERREF, &order_guid_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-owner-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -54,134 +54,147 @@
{
const GValue* val;
gchar* buf;
- GncOwnerType type;
+ GncOwnerType type;
GUID guid;
- QofBook* book;
- GncOwner owner;
- GUID* pGuid = NULL;
+ QofBook* book;
+ GncOwner owner;
+ GUID* pGuid = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
- book = be->primary_book;
+ book = be->primary_book;
buf = g_strdup_printf( "%s_type", table_row->col_name );
val = gnc_sql_row_get_value_at_col_name( row, buf );
- type = (GncOwnerType)gnc_sql_get_integer_value( val );
+ type = (GncOwnerType)gnc_sql_get_integer_value( val );
g_free( buf );
buf = g_strdup_printf( "%s_guid", table_row->col_name );
val = gnc_sql_row_get_value_at_col_name( row, buf );
g_free( buf );
- if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
+ if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+ {
string_to_guid( g_value_get_string( val ), &guid );
- pGuid = &guid;
- }
+ pGuid = &guid;
+ }
- switch( type ) {
- case GNC_OWNER_CUSTOMER:
- {
- GncCustomer *cust = NULL;
+ switch ( type )
+ {
+ case GNC_OWNER_CUSTOMER:
+ {
+ GncCustomer *cust = NULL;
- if( pGuid != NULL ) {
- cust = gncCustomerLookup( book, pGuid );
- if( cust == NULL ) {
- cust = gncCustomerCreate( book );
- gncCustomerSetGUID( cust, &guid );
- }
- }
- gncOwnerInitCustomer( &owner, cust );
- break;
- }
+ if ( pGuid != NULL )
+ {
+ cust = gncCustomerLookup( book, pGuid );
+ if ( cust == NULL )
+ {
+ cust = gncCustomerCreate( book );
+ gncCustomerSetGUID( cust, &guid );
+ }
+ }
+ gncOwnerInitCustomer( &owner, cust );
+ break;
+ }
- case GNC_OWNER_JOB:
- {
- GncJob *job = NULL;
+ case GNC_OWNER_JOB:
+ {
+ GncJob *job = NULL;
- if( pGuid != NULL ) {
- job = gncJobLookup( book, pGuid );
- if( job == NULL ) {
- job = gncJobCreate( book );
- gncJobSetGUID( job, &guid );
- }
- }
- gncOwnerInitJob( &owner, job );
- break;
- }
+ if ( pGuid != NULL )
+ {
+ job = gncJobLookup( book, pGuid );
+ if ( job == NULL )
+ {
+ job = gncJobCreate( book );
+ gncJobSetGUID( job, &guid );
+ }
+ }
+ gncOwnerInitJob( &owner, job );
+ break;
+ }
- case GNC_OWNER_VENDOR:
- {
- GncVendor *vendor = NULL;
+ case GNC_OWNER_VENDOR:
+ {
+ GncVendor *vendor = NULL;
- if( pGuid != NULL ) {
- vendor = gncVendorLookup( book, pGuid );
- if( vendor == NULL ) {
- vendor = gncVendorCreate( book );
- gncVendorSetGUID( vendor, &guid );
- }
- }
- gncOwnerInitVendor( &owner, vendor );
- break;
- }
+ if ( pGuid != NULL )
+ {
+ vendor = gncVendorLookup( book, pGuid );
+ if ( vendor == NULL )
+ {
+ vendor = gncVendorCreate( book );
+ gncVendorSetGUID( vendor, &guid );
+ }
+ }
+ gncOwnerInitVendor( &owner, vendor );
+ break;
+ }
- case GNC_OWNER_EMPLOYEE:
- {
- GncEmployee *employee = NULL;
+ case GNC_OWNER_EMPLOYEE:
+ {
+ GncEmployee *employee = NULL;
- if( pGuid != NULL ) {
- employee = gncEmployeeLookup( book, pGuid );
- if( employee == NULL ) {
- employee = gncEmployeeCreate( book );
- gncEmployeeSetGUID( employee, &guid );
- }
- }
- gncOwnerInitEmployee( &owner, employee );
- break;
- }
+ if ( pGuid != NULL )
+ {
+ employee = gncEmployeeLookup( book, pGuid );
+ if ( employee == NULL )
+ {
+ employee = gncEmployeeCreate( book );
+ gncEmployeeSetGUID( employee, &guid );
+ }
+ }
+ gncOwnerInitEmployee( &owner, employee );
+ break;
+ }
- default:
- PWARN("Invalid owner type: %d\n", type );
- }
+ default:
+ PWARN("Invalid owner type: %d\n", type );
+ }
- if( table_row->gobj_param_name != NULL ) {
- g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
- } else {
- (*setter)( pObject, &owner );
- }
+ if ( table_row->gobj_param_name != NULL )
+ {
+ g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
+ }
+ else
+ {
+ (*setter)( pObject, &owner );
+ }
}
static void
add_owner_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
- GList** pList )
+ GList** pList )
{
- GncSqlColumnInfo* info;
+ GncSqlColumnInfo* info;
gchar* buf;
- const gchar* type;
+ const gchar* type;
- g_return_if_fail( be != NULL );
- g_return_if_fail( table_row != NULL );
- g_return_if_fail( pList != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( table_row != NULL );
+ g_return_if_fail( pList != NULL );
buf = g_strdup_printf( "%s_type", table_row->col_name );
- info = g_new0( GncSqlColumnInfo, 1 );
- info->name = buf;
- info->type = BCT_INT;
- info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
- info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
- info->size = table_row->size;
- info->is_unicode = FALSE;
- *pList = g_list_append( *pList, info );
+ info = g_new0( GncSqlColumnInfo, 1 );
+ info->name = buf;
+ info->type = BCT_INT;
+ info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+ info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+ info->size = table_row->size;
+ info->is_unicode = FALSE;
+ *pList = g_list_append( *pList, info );
- buf = g_strdup_printf( "%s_guid", table_row->col_name );
- info = g_new0( GncSqlColumnInfo, 1 );
- info->name = buf;
- info->type = BCT_STRING;
- info->size = GUID_ENCODING_LENGTH;
- info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
- info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
- info->is_unicode = FALSE;
- *pList = g_list_append( *pList, info );
+ buf = g_strdup_printf( "%s_guid", table_row->col_name );
+ info = g_new0( GncSqlColumnInfo, 1 );
+ info->name = buf;
+ info->type = BCT_STRING;
+ info->size = GUID_ENCODING_LENGTH;
+ info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
+ info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
+ info->is_unicode = FALSE;
+ *pList = g_list_append( *pList, info );
}
static void
@@ -190,95 +203,102 @@
gchar* buf;
buf = g_strdup_printf( "%s_type", table_row->col_name );
- (*pList) = g_list_append( (*pList), buf );
+ (*pList) = g_list_append( (*pList), buf );
buf = g_strdup_printf( "%s_guid", table_row->col_name );
- (*pList) = g_list_append( (*pList), buf );
+ (*pList) = g_list_append( (*pList), buf );
}
static void
add_gvalue_owner_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
- const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
+ const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
{
GValue* subfield_value;
GncOwner* owner;
- gchar* buf;
+ gchar* buf;
const GUID* guid;
gchar guid_buf[GUID_ENCODING_LENGTH+1];
- GncOwnerType type;
- QofInstance* inst = NULL;
+ GncOwnerType type;
+ QofInstance* inst = NULL;
OwnerGetterFunc getter;
- g_return_if_fail( be != NULL );
- g_return_if_fail( obj_name != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( obj_name != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
- getter = (OwnerGetterFunc)gnc_sql_get_getter( obj_name, table_row );
+ getter = (OwnerGetterFunc)gnc_sql_get_getter( obj_name, table_row );
owner = (*getter)( pObject );
- if( owner != NULL ) {
- buf = g_strdup_printf( "%s_type", table_row->col_name );
- subfield_value = g_new0( GValue, 1 );
+ if ( owner != NULL )
+ {
+ buf = g_strdup_printf( "%s_type", table_row->col_name );
+ subfield_value = g_new0( GValue, 1 );
g_value_init( subfield_value, G_TYPE_INT );
type = gncOwnerGetType( owner );
g_value_set_int( subfield_value, type );
- (*pList) = g_slist_append( (*pList), subfield_value );
- g_free( buf );
+ (*pList) = g_slist_append( (*pList), subfield_value );
+ g_free( buf );
- buf = g_strdup_printf( "%s_guid", table_row->col_name );
- subfield_value = g_new0( GValue, 1 );
- switch( type ) {
- case GNC_OWNER_CUSTOMER:
- inst = QOF_INSTANCE(gncOwnerGetCustomer( owner ));
- break;
+ buf = g_strdup_printf( "%s_guid", table_row->col_name );
+ subfield_value = g_new0( GValue, 1 );
+ switch ( type )
+ {
+ case GNC_OWNER_CUSTOMER:
+ inst = QOF_INSTANCE(gncOwnerGetCustomer( owner ));
+ break;
- case GNC_OWNER_JOB:
- inst = QOF_INSTANCE(gncOwnerGetJob( owner ));
- break;
+ case GNC_OWNER_JOB:
+ inst = QOF_INSTANCE(gncOwnerGetJob( owner ));
+ break;
- case GNC_OWNER_VENDOR:
- inst = QOF_INSTANCE(gncOwnerGetVendor( owner ));
- break;
+ case GNC_OWNER_VENDOR:
+ inst = QOF_INSTANCE(gncOwnerGetVendor( owner ));
+ break;
- case GNC_OWNER_EMPLOYEE:
- inst = QOF_INSTANCE(gncOwnerGetEmployee( owner ));
- break;
+ case GNC_OWNER_EMPLOYEE:
+ inst = QOF_INSTANCE(gncOwnerGetEmployee( owner ));
+ break;
- default:
- PWARN("Invalid owner type: %d\n", type );
- }
+ default:
+ PWARN("Invalid owner type: %d\n", type );
+ }
g_value_init( subfield_value, G_TYPE_STRING );
- if( inst != NULL ) {
- guid = qof_instance_get_guid( inst );
- if( guid != NULL ) {
- (void)guid_to_string_buff( guid, guid_buf );
- g_value_take_string( subfield_value, g_strdup_printf( "%s", guid_buf ) );
- }
- }
- (*pList) = g_slist_append( (*pList), subfield_value );
- g_free( buf );
- } else {
- subfield_value = g_new0( GValue, 1 );
- g_value_init( subfield_value, G_TYPE_STRING );
- g_value_set_string( subfield_value, "NULL" );
- (*pList) = g_slist_append( (*pList), subfield_value );
- subfield_value = g_new0( GValue, 1 );
- g_value_init( subfield_value, G_TYPE_STRING );
- g_value_set_string( subfield_value, "NULL" );
- (*pList) = g_slist_append( (*pList), subfield_value );
- }
+ if ( inst != NULL )
+ {
+ guid = qof_instance_get_guid( inst );
+ if ( guid != NULL )
+ {
+ (void)guid_to_string_buff( guid, guid_buf );
+ g_value_take_string( subfield_value, g_strdup_printf( "%s", guid_buf ) );
+ }
+ }
+ (*pList) = g_slist_append( (*pList), subfield_value );
+ g_free( buf );
+ }
+ else
+ {
+ subfield_value = g_new0( GValue, 1 );
+ g_value_init( subfield_value, G_TYPE_STRING );
+ g_value_set_string( subfield_value, "NULL" );
+ (*pList) = g_slist_append( (*pList), subfield_value );
+ subfield_value = g_new0( GValue, 1 );
+ g_value_init( subfield_value, G_TYPE_STRING );
+ g_value_set_string( subfield_value, "NULL" );
+ (*pList) = g_slist_append( (*pList), subfield_value );
+ }
}
static GncSqlColumnTypeHandler owner_handler
- = { load_owner,
- add_owner_col_info_to_list,
- add_colname_to_list,
- add_gvalue_owner_to_slist };
+= { load_owner,
+ add_owner_col_info_to_list,
+ add_colname_to_list,
+ add_gvalue_owner_to_slist
+ };
/* ================================================================= */
void
gnc_owner_sql_initialize( void )
{
- gnc_sql_register_col_type_handler( CT_OWNERREF, &owner_handler );
+ gnc_sql_register_col_type_handler( CT_OWNERREF, &owner_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-tax-table-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -48,7 +48,8 @@
static void set_invisible( gpointer data, gboolean value );
-typedef struct {
+typedef struct
+{
GncSqlBackend* be;
const GUID* guid;
} guid_info_t;
@@ -65,16 +66,20 @@
static GncSqlColumnTableEntry tt_col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
- { "refcount", CT_INT64, 0, COL_NNUL, NULL, GNC_TT_REFCOUNT },
- { "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncTaxTableGetInvisible, (QofSetterFunc)set_invisible },
-/* { "child", CT_TAXTABLEREF, 0, 0, NULL, NULL,
- get_child, (QofSetterFunc)gncTaxTableSetChild }, */
- { "parent", CT_TAXTABLEREF, 0, 0, NULL, NULL,
- (QofAccessFunc)gncTaxTableGetParent, set_parent },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
+ { "refcount", CT_INT64, 0, COL_NNUL, NULL, GNC_TT_REFCOUNT },
+ {
+ "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncTaxTableGetInvisible, (QofSetterFunc)set_invisible
+ },
+ /* { "child", CT_TAXTABLEREF, 0, 0, NULL, NULL,
+ get_child, (QofSetterFunc)gncTaxTableSetChild }, */
+ {
+ "parent", CT_TAXTABLEREF, 0, 0, NULL, NULL,
+ (QofAccessFunc)gncTaxTableGetParent, set_parent
+ },
+ { NULL }
};
#define TTENTRIES_TABLE_NAME "taxtable_entries"
@@ -82,16 +87,24 @@
static GncSqlColumnTableEntry ttentries_col_table[] =
{
- { "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
- { "taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncTaxTableEntryGetTable, set_obj_guid },
- { "account", CT_ACCOUNTREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncTaxTableEntryGetAccount, (QofSetterFunc)gncTaxTableEntrySetAccount },
- { "amount", CT_NUMERIC, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncTaxTableEntryGetAmount, (QofSetterFunc)gncTaxTableEntrySetAmount },
- { "type", CT_INT, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncTaxTableEntryGetType, (QofSetterFunc)gncTaxTableEntrySetType },
- { NULL }
+ { "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
+ {
+ "taxtable", CT_TAXTABLEREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncTaxTableEntryGetTable, set_obj_guid
+ },
+ {
+ "account", CT_ACCOUNTREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncTaxTableEntryGetAccount, (QofSetterFunc)gncTaxTableEntrySetAccount
+ },
+ {
+ "amount", CT_NUMERIC, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncTaxTableEntryGetAmount, (QofSetterFunc)gncTaxTableEntrySetAmount
+ },
+ {
+ "type", CT_INT, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncTaxTableEntryGetType, (QofSetterFunc)gncTaxTableEntrySetType
+ },
+ { NULL }
};
/* Special column table because we need to be able to access the table by
@@ -107,7 +120,7 @@
{
guid_info_t* pInfo = (guid_info_t*)pObject;
- g_return_val_if_fail( pInfo != NULL, NULL );
+ g_return_val_if_fail( pInfo != NULL, NULL );
return (gpointer)pInfo->guid;
}
@@ -121,54 +134,56 @@
static void
set_invisible( gpointer data, gboolean value )
{
- GncTaxTable* tt = GNC_TAXTABLE(data);
+ GncTaxTable* tt = GNC_TAXTABLE(data);
- g_return_if_fail( data != NULL );
- g_return_if_fail( GNC_IS_TAXTABLE(data) );
+ g_return_if_fail( data != NULL );
+ g_return_if_fail( GNC_IS_TAXTABLE(data) );
- if( value ) {
- gncTaxTableMakeInvisible( tt );
- }
+ if ( value )
+ {
+ gncTaxTableMakeInvisible( tt );
+ }
}
static gpointer
get_child( gpointer pObject, const QofParam* param )
{
- GncTaxTable* tt = GNC_TAXTABLE(pObject);
+ GncTaxTable* tt = GNC_TAXTABLE(pObject);
- g_return_val_if_fail( pObject != NULL, NULL );
- g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
+ g_return_val_if_fail( pObject != NULL, NULL );
+ g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
- return gncTaxTableGetChild( tt );
+ return gncTaxTableGetChild( tt );
}
static void
set_parent( gpointer data, gpointer value )
{
- GncTaxTable* tt = GNC_TAXTABLE(data);
- GncTaxTable* parent;
+ GncTaxTable* tt = GNC_TAXTABLE(data);
+ GncTaxTable* parent;
- g_return_if_fail( data != NULL );
- g_return_if_fail( GNC_IS_TAXTABLE(data) );
+ g_return_if_fail( data != NULL );
+ g_return_if_fail( GNC_IS_TAXTABLE(data) );
- if( value != NULL ) {
- parent = GNC_TAXTABLE(value);
- gncTaxTableSetParent( tt, parent );
- gncTaxTableSetChild( parent, tt );
- }
+ if ( value != NULL )
+ {
+ parent = GNC_TAXTABLE(value);
+ gncTaxTableSetParent( tt, parent );
+ gncTaxTableSetChild( parent, tt );
+ }
}
static void
load_single_ttentry( GncSqlBackend* be, GncSqlRow* row, GncTaxTable* tt )
{
- GncTaxTableEntry* e = gncTaxTableEntryCreate();
+ GncTaxTableEntry* e = gncTaxTableEntryCreate();
- g_return_if_fail( be != NULL );
- g_return_if_fail( row!= NULL );
- g_return_if_fail( tt != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( tt != NULL );
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, e, ttentries_col_table );
- gncTaxTableAddEntry( tt, e );
+ gncTaxTableAddEntry( tt, e );
}
static void
@@ -177,31 +192,33 @@
GncSqlResult* result;
gchar guid_buf[GUID_ENCODING_LENGTH+1];
GValue value;
- gchar* buf;
- GncSqlStatement* stmt;
- GError* error = NULL;
+ gchar* buf;
+ GncSqlStatement* stmt;
+ GError* error = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( tt != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( tt != NULL );
guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(tt) ), guid_buf );
memset( &value, 0, sizeof( GValue ) );
g_value_init( &value, G_TYPE_STRING );
g_value_set_string( &value, guid_buf );
- buf = g_strdup_printf( "SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf );
- stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
- g_free( buf );
+ buf = g_strdup_printf( "SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf );
+ stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
+ g_free( buf );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
load_single_ttentry( be, row, tt );
- row = gnc_sql_result_get_next_row( result );
+ row = gnc_sql_result_get_next_row( result );
}
- gnc_sql_result_dispose( result );
+ gnc_sql_result_dispose( result );
}
}
@@ -209,19 +226,20 @@
load_single_taxtable( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncTaxTable* tt;
+ GncTaxTable* tt;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
guid = gnc_sql_load_guid( be, row );
tt = gncTaxTableLookup( be->primary_book, guid );
- if( tt == NULL ) {
+ if ( tt == NULL )
+ {
tt = gncTaxTableCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, tt, tt_col_table );
gnc_sql_slots_load( be, QOF_INSTANCE(tt) );
- load_taxtable_entries( be, tt );
+ load_taxtable_entries( be, tt );
qof_instance_mark_clean( QOF_INSTANCE(tt) );
}
@@ -232,21 +250,23 @@
GncSqlStatement* stmt;
GncSqlResult* result;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
/* First time, create the query */
stmt = gnc_sql_create_select_statement( be, TT_TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
load_single_taxtable( be, row );
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
}
}
@@ -254,27 +274,33 @@
static void
create_taxtable_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TT_TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TT_TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table );
- } else if( version == 1 ) {
- /* Upgrade 64 bit int handling */
- gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table );
- gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION );
}
+ else if ( version == 1 )
+ {
+ /* Upgrade 64 bit int handling */
+ gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table );
+ gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION );
+ }
- version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table );
- } else if( version == 1 ) {
- /* Upgrade 64 bit int handling */
- gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
- gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION );
}
+ else if ( version == 1 )
+ {
+ /* Upgrade 64 bit int handling */
+ gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
+ gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION );
+ }
}
/* ================================================================= */
@@ -283,37 +309,38 @@
{
guid_info_t guid_info;
- g_return_val_if_fail( be != NULL, FALSE );
- g_return_val_if_fail( guid != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( guid != NULL, FALSE );
guid_info.be = be;
guid_info.guid = guid;
return gnc_sql_do_db_operation( be, OP_DB_DELETE, TTENTRIES_TABLE_NAME,
- TTENTRIES_TABLE_NAME, &guid_info, guid_col_table );
+ TTENTRIES_TABLE_NAME, &guid_info, guid_col_table );
}
static gboolean
save_tt_entries( GncSqlBackend* be, const GUID* guid, GList* entries )
{
- GList* entry;
- gboolean is_ok;
+ GList* entry;
+ gboolean is_ok;
- g_return_val_if_fail( be != NULL, FALSE );
- g_return_val_if_fail( guid != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( guid != NULL, FALSE );
/* First, delete the old entries for this object */
is_ok = delete_all_tt_entries( be, guid );
- for( entry = entries; entry != NULL && is_ok; entry = entry->next ) {
- GncTaxTableEntry* e = (GncTaxTableEntry*)entry->data;
- is_ok = gnc_sql_do_db_operation( be,
- OP_DB_INSERT,
- TTENTRIES_TABLE_NAME,
- GNC_ID_TAXTABLE, e,
- ttentries_col_table );
+ for ( entry = entries; entry != NULL && is_ok; entry = entry->next )
+ {
+ GncTaxTableEntry* e = (GncTaxTableEntry*)entry->data;
+ is_ok = gnc_sql_do_db_operation( be,
+ OP_DB_INSERT,
+ TTENTRIES_TABLE_NAME,
+ GNC_ID_TAXTABLE, e,
+ ttentries_col_table );
}
- return is_ok;
+ return is_ok;
}
static gboolean
@@ -321,106 +348,126 @@
{
GncTaxTable* tt;
const GUID* guid;
- gint op;
- gboolean is_infant;
- gboolean is_ok;
+ gint op;
+ gboolean is_infant;
+ gboolean is_ok;
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_TAXTABLE(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_TAXTABLE(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
tt = GNC_TAXTABLE(inst);
- is_infant = qof_instance_get_infant( inst );
- if( qof_instance_get_destroying( inst ) ) {
- op = OP_DB_DELETE;
- } else if( be->is_pristine_db || is_infant ) {
- op = OP_DB_INSERT;
- } else {
- op = OP_DB_UPDATE;
- }
+ is_infant = qof_instance_get_infant( inst );
+ if ( qof_instance_get_destroying( inst ) )
+ {
+ op = OP_DB_DELETE;
+ }
+ else if ( be->is_pristine_db || is_infant )
+ {
+ op = OP_DB_INSERT;
+ }
+ else
+ {
+ op = OP_DB_UPDATE;
+ }
is_ok = gnc_sql_do_db_operation( be, op, TT_TABLE_NAME, GNC_ID_TAXTABLE, tt, tt_col_table );
- if( is_ok ) {
- // Now, commit or delete any slots and tax table entries
- guid = qof_instance_get_guid( inst );
- if( !qof_instance_get_destroying(inst) ) {
- is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
- if( is_ok ) {
- is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) );
- }
- } else {
- is_ok = gnc_sql_slots_delete( be, guid );
- if( is_ok ) {
- is_ok = delete_all_tt_entries( be, guid );
- }
- }
- }
+ if ( is_ok )
+ {
+ // Now, commit or delete any slots and tax table entries
+ guid = qof_instance_get_guid( inst );
+ if ( !qof_instance_get_destroying(inst) )
+ {
+ is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+ if ( is_ok )
+ {
+ is_ok = save_tt_entries( be, guid, gncTaxTableGetEntries( tt ) );
+ }
+ }
+ else
+ {
+ is_ok = gnc_sql_slots_delete( be, guid );
+ if ( is_ok )
+ {
+ is_ok = delete_all_tt_entries( be, guid );
+ }
+ }
+ }
- return is_ok;
+ return is_ok;
}
/* ================================================================= */
static void
save_next_taxtable( QofInstance* inst, gpointer data )
{
- write_objects_t* s = (write_objects_t*)data;
+ write_objects_t* s = (write_objects_t*)data;
- if( s->is_ok ) {
- s->is_ok = save_taxtable( s->be, inst );
- }
+ if ( s->is_ok )
+ {
+ s->is_ok = save_taxtable( s->be, inst );
+ }
}
static gboolean
write_taxtables( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_TAXTABLE, be->primary_book, save_next_taxtable, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
static void
load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row,
- QofSetterFunc setter, gpointer pObject,
- const GncSqlColumnTableEntry* table_row )
+ QofSetterFunc setter, gpointer pObject,
+ const GncSqlColumnTableEntry* table_row )
{
const GValue* val;
GUID guid;
- GncTaxTable* taxtable = NULL;
+ GncTaxTable* taxtable = NULL;
- g_return_if_fail( be != NULL );
- g_return_if_fail( row != NULL );
- g_return_if_fail( pObject != NULL );
- g_return_if_fail( table_row != NULL );
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( row != NULL );
+ g_return_if_fail( pObject != NULL );
+ g_return_if_fail( table_row != NULL );
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
- if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
+ if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
+ {
string_to_guid( g_value_get_string( val ), &guid );
- taxtable = gncTaxTableLookup( be->primary_book, &guid );
- if( taxtable != NULL ) {
- if( table_row->gobj_param_name != NULL ) {
- g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL );
- } else {
- (*setter)( pObject, (const gpointer)taxtable );
- }
- } else {
- PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) );
- }
+ taxtable = gncTaxTableLookup( be->primary_book, &guid );
+ if ( taxtable != NULL )
+ {
+ if ( table_row->gobj_param_name != NULL )
+ {
+ g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL );
+ }
+ else
+ {
+ (*setter)( pObject, (const gpointer)taxtable );
+ }
+ }
+ else
+ {
+ PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) );
+ }
}
}
static GncSqlColumnTypeHandler taxtable_guid_handler
- = { load_taxtable_guid,
- gnc_sql_add_objectref_guid_col_info_to_list,
- gnc_sql_add_colname_to_list,
- gnc_sql_add_gvalue_objectref_guid_to_slist };
+= { load_taxtable_guid,
+ gnc_sql_add_objectref_guid_col_info_to_list,
+ gnc_sql_add_colname_to_list,
+ gnc_sql_add_gvalue_objectref_guid_to_slist
+ };
/* ================================================================= */
void
gnc_taxtable_sql_initialize( void )
@@ -432,13 +479,13 @@
save_taxtable, /* commit */
load_all_taxtables, /* initial_load */
create_taxtable_tables, /* create_tables */
- NULL, NULL, NULL,
- write_taxtables /* write */
+ NULL, NULL, NULL,
+ write_taxtables /* write */
};
qof_object_register_backend( GNC_ID_TAXTABLE, GNC_SQL_BACKEND, &be_data );
- gnc_sql_register_col_type_handler( CT_TAXTABLEREF, &taxtable_guid_handler );
+ gnc_sql_register_col_type_handler( CT_TAXTABLEREF, &taxtable_guid_handler );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c
===================================================================
--- gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/sql/gnc-vendor-sql.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -63,40 +63,45 @@
static GncSqlColumnTableEntry col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
- { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
- { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, VENDOR_ID },
- { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, VENDOR_NOTES },
- { "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncVendorGetCurrency, (QofSetterFunc)gncVendorSetCurrency },
- { "active", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
- (QofAccessFunc)gncVendorGetActive, (QofSetterFunc)gncVendorSetActive },
- { "tax_override", CT_BOOLEAN, 0, COL_NNUL, NULL, VENDOR_TAX_OVERRIDE },
- { "addr", CT_ADDRESS, 0, 0, NULL, VENDOR_ADDR },
- { "terms", CT_BILLTERMREF, 0, 0, NULL, VENDOR_TERMS },
- { "tax_inc", CT_STRING, MAX_TAX_INC_LEN, 0, NULL, VENDOR_TAX_INC },
- { "tax_table", CT_TAXTABLEREF, 0, 0, NULL, VENDOR_TAX_TABLE },
- { NULL }
+ { "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
+ { "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, "name" },
+ { "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, VENDOR_ID },
+ { "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, VENDOR_NOTES },
+ {
+ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncVendorGetCurrency, (QofSetterFunc)gncVendorSetCurrency
+ },
+ {
+ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)gncVendorGetActive, (QofSetterFunc)gncVendorSetActive
+ },
+ { "tax_override", CT_BOOLEAN, 0, COL_NNUL, NULL, VENDOR_TAX_OVERRIDE },
+ { "addr", CT_ADDRESS, 0, 0, NULL, VENDOR_ADDR },
+ { "terms", CT_BILLTERMREF, 0, 0, NULL, VENDOR_TERMS },
+ { "tax_inc", CT_STRING, MAX_TAX_INC_LEN, 0, NULL, VENDOR_TAX_INC },
+ { "tax_table", CT_TAXTABLEREF, 0, 0, NULL, VENDOR_TAX_TABLE },
+ { NULL }
};
static GncVendor*
load_single_vendor( GncSqlBackend* be, GncSqlRow* row )
{
const GUID* guid;
- GncVendor* pVendor;
+ GncVendor* pVendor;
- g_return_val_if_fail( be != NULL, NULL );
- g_return_val_if_fail( row != NULL, NULL );
+ g_return_val_if_fail( be != NULL, NULL );
+ g_return_val_if_fail( row != NULL, NULL );
guid = gnc_sql_load_guid( be, row );
pVendor = gncVendorLookup( be->primary_book, guid );
- if( pVendor == NULL ) {
+ if ( pVendor == NULL )
+ {
pVendor = gncVendorCreate( be->primary_book );
}
gnc_sql_load_object( be, row, GNC_ID_VENDOR, pVendor, col_table );
qof_instance_mark_clean( QOF_INSTANCE(pVendor) );
- return pVendor;
+ return pVendor;
}
static void
@@ -106,30 +111,34 @@
GncSqlResult* result;
QofBook* pBook;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
pBook = be->primary_book;
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
result = gnc_sql_execute_select_statement( be, stmt );
- gnc_sql_statement_dispose( stmt );
- if( result != NULL ) {
+ gnc_sql_statement_dispose( stmt );
+ if ( result != NULL )
+ {
GncSqlRow* row;
- GList* list = NULL;
+ GList* list = NULL;
- row = gnc_sql_result_get_first_row( result );
- while( row != NULL ) {
+ row = gnc_sql_result_get_first_row( result );
+ while ( row != NULL )
+ {
GncVendor* pVendor = load_single_vendor( be, row );
- if( pVendor != NULL ) {
- list = g_list_append( list, pVendor );
- }
- row = gnc_sql_result_get_next_row( result );
- }
- gnc_sql_result_dispose( result );
+ if ( pVendor != NULL )
+ {
+ list = g_list_append( list, pVendor );
+ }
+ row = gnc_sql_result_get_next_row( result );
+ }
+ gnc_sql_result_dispose( result );
- if( list != NULL ) {
- gnc_sql_slots_load_for_list( be, list );
- }
+ if ( list != NULL )
+ {
+ gnc_sql_slots_load_for_list( be, list );
+ }
}
}
@@ -137,12 +146,13 @@
static void
create_vendor_tables( GncSqlBackend* be )
{
- gint version;
+ gint version;
- g_return_if_fail( be != NULL );
+ g_return_if_fail( be != NULL );
- version = gnc_sql_get_table_version( be, TABLE_NAME );
- if( version == 0 ) {
+ version = gnc_sql_get_table_version( be, TABLE_NAME );
+ if ( version == 0 )
+ {
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
}
}
@@ -153,43 +163,54 @@
{
GncVendor* v;
const GUID* guid;
- gint op;
- gboolean is_infant;
- gboolean is_ok = TRUE;
+ gint op;
+ gboolean is_infant;
+ gboolean is_ok = TRUE;
- g_return_val_if_fail( inst != NULL, FALSE );
- g_return_val_if_fail( GNC_IS_VENDOR(inst), FALSE );
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( inst != NULL, FALSE );
+ g_return_val_if_fail( GNC_IS_VENDOR(inst), FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
v = GNC_VENDOR(inst);
- is_infant = qof_instance_get_infant( inst );
- if( qof_instance_get_destroying( inst ) ) {
- op = OP_DB_DELETE;
- } else if( be->is_pristine_db || is_infant ) {
- op = OP_DB_INSERT;
- } else {
- op = OP_DB_UPDATE;
- }
- if( op != OP_DB_DELETE ) {
- // Ensure the commodity is in the db
- is_ok = gnc_sql_save_commodity( be, gncVendorGetCurrency( v ) );
- }
- if( is_ok ) {
- is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_VENDOR, v, col_table );
- }
+ is_infant = qof_instance_get_infant( inst );
+ if ( qof_instance_get_destroying( inst ) )
+ {
+ op = OP_DB_DELETE;
+ }
+ else if ( be->is_pristine_db || is_infant )
+ {
+ op = OP_DB_INSERT;
+ }
+ else
+ {
+ op = OP_DB_UPDATE;
+ }
+ if ( op != OP_DB_DELETE )
+ {
+ // Ensure the commodity is in the db
+ is_ok = gnc_sql_save_commodity( be, gncVendorGetCurrency( v ) );
+ }
+ if ( is_ok )
+ {
+ is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_VENDOR, v, col_table );
+ }
- if( is_ok ) {
- // Now, commit or delete any slots
- guid = qof_instance_get_guid( inst );
- if( !qof_instance_get_destroying(inst) ) {
- is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
- } else {
- is_ok = gnc_sql_slots_delete( be, guid );
- }
- }
+ if ( is_ok )
+ {
+ // Now, commit or delete any slots
+ guid = qof_instance_get_guid( inst );
+ if ( !qof_instance_get_destroying(inst) )
+ {
+ is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
+ }
+ else
+ {
+ is_ok = gnc_sql_slots_delete( be, guid );
+ }
+ }
- return is_ok;
+ return is_ok;
}
/* ================================================================= */
@@ -198,13 +219,14 @@
{
const char *id;
- g_return_val_if_fail( vendor != NULL, FALSE );
+ g_return_val_if_fail( vendor != NULL, FALSE );
/* make sure this is a valid vendor before we save it -- should have an ID */
id = gncVendorGetID( vendor );
- if( id == NULL || *id == '\0' ) {
+ if ( id == NULL || *id == '\0' )
+ {
return FALSE;
- }
+ }
return TRUE;
}
@@ -212,29 +234,30 @@
static void
write_single_vendor( QofInstance *term_p, gpointer data_p )
{
- write_objects_t* s = (write_objects_t*)data_p;
+ write_objects_t* s = (write_objects_t*)data_p;
- g_return_if_fail( term_p != NULL );
- g_return_if_fail( GNC_IS_VENDOR(term_p) );
- g_return_if_fail( data_p != NULL );
+ g_return_if_fail( term_p != NULL );
+ g_return_if_fail( GNC_IS_VENDOR(term_p) );
+ g_return_if_fail( data_p != NULL );
- if( s->is_ok && vendor_should_be_saved( GNC_VENDOR(term_p) ) ) {
- s->is_ok = save_vendor( s->be, term_p );
- }
+ if ( s->is_ok && vendor_should_be_saved( GNC_VENDOR(term_p) ) )
+ {
+ s->is_ok = save_vendor( s->be, term_p );
+ }
}
static gboolean
write_vendors( GncSqlBackend* be )
{
- write_objects_t data;
+ write_objects_t data;
- g_return_val_if_fail( be != NULL, FALSE );
+ g_return_val_if_fail( be != NULL, FALSE );
- data.be = be;
- data.is_ok = TRUE;
+ data.be = be;
+ data.is_ok = TRUE;
qof_object_foreach( GNC_ID_VENDOR, be->primary_book, write_single_vendor, &data );
- return data.is_ok;
+ return data.is_ok;
}
/* ================================================================= */
@@ -248,8 +271,8 @@
save_vendor, /* commit */
load_all_vendors, /* initial_load */
create_vendor_tables, /* create_tables */
- NULL, NULL, NULL,
- write_vendors /* write */
+ NULL, NULL, NULL,
+ write_vendors /* write */
};
qof_object_register_backend( GNC_ID_VENDOR, GNC_SQL_BACKEND, &be_data );
Modified: gnucash/trunk/src/business/business-core/test/test-address.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-address.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-address.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-address.c
* object definition/initialization for Address
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
* Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
*
@@ -32,67 +32,68 @@
static void
test_string_fcn (GncAddress *address, const char *message,
- void (*set) (GncAddress *, const char *str),
- const char * (*get)(const GncAddress *));
+ void (*set) (GncAddress *, const char *str),
+ const char * (*get)(const GncAddress *));
static void
test_address (void)
{
- QofInstance *ent;
- GncAddress *address;
- QofBook *book = qof_book_new ();
+ QofInstance *ent;
+ GncAddress *address;
+ QofBook *book = qof_book_new ();
- ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
- ent->e_type = "asdf";
+ ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
+ ent->e_type = "asdf";
- /* Test creation/destruction */
- {
- do_test (gncAddressCreate (NULL, NULL) == NULL, "address create NULL");
+ /* Test creation/destruction */
+ {
+ do_test (gncAddressCreate (NULL, NULL) == NULL, "address create NULL");
- address = gncAddressCreate (book, ent);
- do_test (address != NULL, "address create");
+ address = gncAddressCreate (book, ent);
+ do_test (address != NULL, "address create");
- gncAddressBeginEdit (address);
- gncAddressDestroy (address);
- success ("create/destroy");
- }
+ gncAddressBeginEdit (address);
+ gncAddressDestroy (address);
+ success ("create/destroy");
+ }
- /* Test setting routines */
- {
- address = gncAddressCreate (book, ent);
- test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
- test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
- test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);
- test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3);
- test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4);
- test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone);
- test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax);
- test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail);
- }
+ /* Test setting routines */
+ {
+ address = gncAddressCreate (book, ent);
+ test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
+ test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
+ test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);
+ test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3);
+ test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4);
+ test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone);
+ test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax);
+ test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail);
+ }
}
static void
test_string_fcn (GncAddress *address, const char *message,
- void (*set) (GncAddress *, const char *str),
- const char * (*get)(const GncAddress *))
+ void (*set) (GncAddress *, const char *str),
+ const char * (*get)(const GncAddress *))
{
- char const *str = get_random_string ();
+ char const *str = get_random_string ();
- do_test (!gncAddressIsDirty (address), "test if start dirty");
- set (address, str);
- do_test (gncAddressIsDirty (address), "test dirty later");
- do_test (safe_strcmp (get (address), str) == 0, message);
- gncAddressClearDirty (address);
+ do_test (!gncAddressIsDirty (address), "test if start dirty");
+ set (address, str);
+ do_test (gncAddressIsDirty (address), "test dirty later");
+ do_test (safe_strcmp (get (address), str) == 0, message);
+ gncAddressClearDirty (address);
}
int
main (int argc, char **argv)
{
- qof_init();
- if(cashobjects_register()) {
- test_address();
- print_test_results();
- }
- qof_close();
- return 0;
+ qof_init();
+ if (cashobjects_register())
+ {
+ test_address();
+ print_test_results();
+ }
+ qof_close();
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-business.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-business.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-business.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-business.c
* Test the business code.
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
*
* This program is free software; you can redistribute it and/or
@@ -42,96 +42,97 @@
static void test_printable (const char *name, gpointer obj);
static void test_get_list (QofBook *, const char *);
-static GncBusinessObject bus_obj = {
- GNC_BUSINESS_VERSION,
- TEST_MODULE_NAME,
- TEST_MODULE_DESC,
- NULL, /* create */
- NULL, /* destroy */
- get_list,
- printable,
+static GncBusinessObject bus_obj =
+{
+ GNC_BUSINESS_VERSION,
+ TEST_MODULE_NAME,
+ TEST_MODULE_DESC,
+ NULL, /* create */
+ NULL, /* destroy */
+ get_list,
+ printable,
};
static void test_business (void)
{
- /* Test the global registration and lookup functions */
- {
- do_test (!gncBusinessRegister (NULL), "register NULL");
- do_test (gncBusinessRegister (&bus_obj), "register test object");
- do_test (!gncBusinessRegister (&bus_obj), "register test object again");
- do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj,
- "lookup our installed object");
- do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL,
- "lookup non-existant business object");
+ /* Test the global registration and lookup functions */
+ {
+ do_test (!gncBusinessRegister (NULL), "register NULL");
+ do_test (gncBusinessRegister (&bus_obj), "register test object");
+ do_test (!gncBusinessRegister (&bus_obj), "register test object again");
+ do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj,
+ "lookup our installed object");
+ do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL,
+ "lookup non-existant business object");
- do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME),
- _(TEST_MODULE_DESC)),
- "test description return");
- }
+ do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME),
+ _(TEST_MODULE_DESC)),
+ "test description return");
+ }
- test_get_list ((QofBook*)1, TEST_MODULE_NAME);
- test_printable (TEST_MODULE_NAME, (gpointer)1);
+ test_get_list ((QofBook*)1, TEST_MODULE_NAME);
+ test_printable (TEST_MODULE_NAME, (gpointer)1);
}
static GList *
get_list (QofBook *book, gboolean show_all)
{
- do_test (book != NULL, "get_list: NULL business");
- success ("called get_list callback");
- return ((GList *)1);
+ do_test (book != NULL, "get_list: NULL business");
+ success ("called get_list callback");
+ return ((GList *)1);
}
static const char *
printable (gpointer obj)
{
- do_test (obj != NULL, "printable: object is NULL");
- success ("called printable callback");
- return ((const char *)obj);
+ do_test (obj != NULL, "printable: object is NULL");
+ success ("called printable callback");
+ return ((const char *)obj);
}
static void
test_get_list (QofBook *book, const char *name)
{
- GList *res;
+ GList *res;
- do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL,
- "business: GetList: NULL, NULL, FALSE");
- do_test (gncBusinessGetList (NULL, name, FALSE) == NULL,
- "business: GetList: NULL, mod_name, FALSE");
- do_test (gncBusinessGetList (book, NULL, FALSE) == NULL,
- "business: GetList: book, NULL, FALSE");
- res = gncBusinessGetList (book, name, FALSE);
- do_test (res != NULL, "business: GetList: book, mod_name, FALSE");
+ do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL,
+ "business: GetList: NULL, NULL, FALSE");
+ do_test (gncBusinessGetList (NULL, name, FALSE) == NULL,
+ "business: GetList: NULL, mod_name, FALSE");
+ do_test (gncBusinessGetList (book, NULL, FALSE) == NULL,
+ "business: GetList: book, NULL, FALSE");
+ res = gncBusinessGetList (book, name, FALSE);
+ do_test (res != NULL, "business: GetList: book, mod_name, FALSE");
}
static void
test_printable (const char *name, gpointer obj)
{
- const char *res;
+ const char *res;
- do_test (gncBusinessPrintable (NULL, NULL) == NULL,
- "business: Printable: NULL, NULL");
- do_test (gncBusinessPrintable (NULL, obj) == NULL,
- "business: Printable: NULL, object");
- do_test (gncBusinessPrintable (name, NULL) == NULL,
- "business: Printable: mod_name, NULL");
- res = gncBusinessPrintable (name, obj);
- do_test (res != NULL, "business: Printable: mod_name, object");
+ do_test (gncBusinessPrintable (NULL, NULL) == NULL,
+ "business: Printable: NULL, NULL");
+ do_test (gncBusinessPrintable (NULL, obj) == NULL,
+ "business: Printable: NULL, object");
+ do_test (gncBusinessPrintable (name, NULL) == NULL,
+ "business: Printable: mod_name, NULL");
+ res = gncBusinessPrintable (name, obj);
+ do_test (res != NULL, "business: Printable: mod_name, object");
}
static void
main_helper (void *closure, int argc, char **argv)
{
- gnc_module_load("gnucash/business-core", 0);
- test_business();
- print_test_results();
- exit(get_rv());
+ gnc_module_load("gnucash/business-core", 0);
+ test_business();
+ print_test_results();
+ exit(get_rv());
}
#endif
int
main (int argc, char **argv)
{
- // scm_boot_guile (argc, argv, main_helper, NULL);
- return 0;
+ // scm_boot_guile (argc, argv, main_helper, NULL);
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-customer.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-customer.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-customer.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-customer.c
* Test the customer object (without Guile/Scheme)
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
* Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
*
@@ -37,184 +37,185 @@
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, const char *str),
- const char * (*get)(const GncCustomer *));
+ void (*set) (GncCustomer *, const char *str),
+ const char * (*get)(const GncCustomer *));
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, gnc_numeric),
- gnc_numeric (*get)(const GncCustomer *));
+ void (*set) (GncCustomer *, gnc_numeric),
+ gnc_numeric (*get)(const GncCustomer *));
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, gboolean),
- gboolean (*get) (const GncCustomer *));
+ void (*set) (GncCustomer *, gboolean),
+ gboolean (*get) (const GncCustomer *));
static void
test_customer (void)
{
- QofBackend *be;
- QofSession *session;
- QofBook *book;
- GncCustomer *customer;
+ QofBackend *be;
+ QofSession *session;
+ QofBook *book;
+ GncCustomer *customer;
- session = qof_session_new();
- be = NULL;
- qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
- book = qof_session_get_book(session);
- be = qof_book_get_backend(book);
+ session = qof_session_new();
+ be = NULL;
+ qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
+ book = qof_session_get_book(session);
+ be = qof_book_get_backend(book);
- /* The book *must* have a backend to pass the test of the 'dirty' flag
- so use a session to use the default QSF. However, until the SQL backend can be used,
- entities remain dirty until the session is saved or closed. */
- do_test (be != NULL, "qsf backend could not be set");
+ /* The book *must* have a backend to pass the test of the 'dirty' flag
+ so use a session to use the default QSF. However, until the SQL backend can be used,
+ entities remain dirty until the session is saved or closed. */
+ do_test (be != NULL, "qsf backend could not be set");
- /* Test creation/destruction */
- {
- do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL");
- customer = gncCustomerCreate (book);
- do_test (customer != NULL, "customer create");
- do_test (gncCustomerGetBook (customer) == book, "getbook");
+ /* Test creation/destruction */
+ {
+ do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL");
+ customer = gncCustomerCreate (book);
+ do_test (customer != NULL, "customer create");
+ do_test (gncCustomerGetBook (customer) == book, "getbook");
- gncCustomerBeginEdit (customer);
- gncCustomerDestroy (customer);
- success ("create/destroy");
- }
+ gncCustomerBeginEdit (customer);
+ gncCustomerDestroy (customer);
+ success ("create/destroy");
+ }
- /* Test setting/getting routines; does the active flag get set right? */
- {
- GUID guid;
+ /* Test setting/getting routines; does the active flag get set right? */
+ {
+ GUID guid;
- test_string_fcn (book, "Id", gncCustomerSetID, gncCustomerGetID);
- test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName);
- test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes);
+ test_string_fcn (book, "Id", gncCustomerSetID, gncCustomerGetID);
+ test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName);
+ test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes);
- //test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);
+ //test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);
- test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
- test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit);
+ test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
+ test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit);
- test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive);
+ test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive);
- do_test (gncCustomerGetAddr (customer) != NULL, "Addr");
- do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr");
+ do_test (gncCustomerGetAddr (customer) != NULL, "Addr");
+ do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr");
- guid_new (&guid);
- customer = gncCustomerCreate (book); count++;
- gncCustomerSetGUID (customer, &guid);
- do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare");
- }
+ guid_new (&guid);
+ customer = gncCustomerCreate (book);
+ count++;
+ gncCustomerSetGUID (customer, &guid);
+ do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare");
+ }
#if 0
- {
- GList *list;
+ {
+ GList *list;
- list = gncBusinessGetList (book, GNC_ID_CUSTOMER, TRUE);
- do_test (list != NULL, "getList all");
- do_test (g_list_length (list) == count, "correct length: all");
- g_list_free (list);
+ list = gncBusinessGetList (book, GNC_ID_CUSTOMER, TRUE);
+ do_test (list != NULL, "getList all");
+ do_test (g_list_length (list) == count, "correct length: all");
+ g_list_free (list);
- list = gncBusinessGetList (book, GNC_ID_CUSTOMER, FALSE);
- do_test (list != NULL, "getList active");
- do_test (g_list_length (list) == 1, "correct length: active");
- g_list_free (list);
- }
+ list = gncBusinessGetList (book, GNC_ID_CUSTOMER, FALSE);
+ do_test (list != NULL, "getList active");
+ do_test (g_list_length (list) == 1, "correct length: active");
+ g_list_free (list);
+ }
#endif
- {
- const char *str = get_random_string();
- const char *res;
+ {
+ const char *str = get_random_string();
+ const char *res;
- res = NULL;
- gncCustomerBeginEdit(customer);
- gncCustomerSetName (customer, str);
- gncCustomerCommitEdit(customer);
- res = qof_object_printable (GNC_ID_CUSTOMER, customer);
- do_test (res != NULL, "Printable NULL?");
- do_test (safe_strcmp (str, res) == 0, "Printable equals");
- }
+ res = NULL;
+ gncCustomerBeginEdit(customer);
+ gncCustomerSetName (customer, str);
+ gncCustomerCommitEdit(customer);
+ res = qof_object_printable (GNC_ID_CUSTOMER, customer);
+ do_test (res != NULL, "Printable NULL?");
+ do_test (safe_strcmp (str, res) == 0, "Printable equals");
+ }
- do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty");
+ do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty");
- /* Test the Entity Table */
- {
- const GUID *guid;
+ /* Test the Entity Table */
+ {
+ const GUID *guid;
- guid = gncCustomerGetGUID (customer);
- do_test (gncCustomerLookup (book, guid) == customer, "Entity Table");
- }
+ guid = gncCustomerGetGUID (customer);
+ do_test (gncCustomerLookup (book, guid) == customer, "Entity Table");
+ }
- /* Note: JobList is tested from the Job tests */
- qof_session_end(session);
+ /* Note: JobList is tested from the Job tests */
+ qof_session_end(session);
}
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, const char *str),
- const char * (*get)(const GncCustomer *))
+ void (*set) (GncCustomer *, const char *str),
+ const char * (*get)(const GncCustomer *))
{
- GncCustomer *customer = gncCustomerCreate (book);
- char const *str = get_random_string ();
+ GncCustomer *customer = gncCustomerCreate (book);
+ char const *str = get_random_string ();
- do_test (!gncCustomerIsDirty (customer), "test if start dirty");
- gncCustomerBeginEdit (customer);
- set (customer, str);
- do_test (gncCustomerIsDirty (customer), "test dirty later");
- gncCustomerCommitEdit (customer);
- do_test (gncCustomerIsDirty (customer), "test dirty after commit");
- do_test (safe_strcmp (get (customer), str) == 0, message);
- gncCustomerSetActive (customer, FALSE);
- count++;
+ do_test (!gncCustomerIsDirty (customer), "test if start dirty");
+ gncCustomerBeginEdit (customer);
+ set (customer, str);
+ do_test (gncCustomerIsDirty (customer), "test dirty later");
+ gncCustomerCommitEdit (customer);
+ do_test (gncCustomerIsDirty (customer), "test dirty after commit");
+ do_test (safe_strcmp (get (customer), str) == 0, message);
+ gncCustomerSetActive (customer, FALSE);
+ count++;
}
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, gnc_numeric),
- gnc_numeric (*get)(const GncCustomer *))
+ void (*set) (GncCustomer *, gnc_numeric),
+ gnc_numeric (*get)(const GncCustomer *))
{
- GncCustomer *customer = gncCustomerCreate (book);
- gnc_numeric num = gnc_numeric_create (17, 1);
+ GncCustomer *customer = gncCustomerCreate (book);
+ gnc_numeric num = gnc_numeric_create (17, 1);
- do_test (!gncCustomerIsDirty (customer), "test if start dirty");
- gncCustomerBeginEdit (customer);
- set (customer, num);
- do_test (gncCustomerIsDirty (customer), "test dirty later");
- gncCustomerCommitEdit (customer);
- do_test (gncCustomerIsDirty (customer), "test dirty after commit");
- do_test (gnc_numeric_equal (get (customer), num), message);
- gncCustomerSetActive (customer, FALSE);
- count++;
+ do_test (!gncCustomerIsDirty (customer), "test if start dirty");
+ gncCustomerBeginEdit (customer);
+ set (customer, num);
+ do_test (gncCustomerIsDirty (customer), "test dirty later");
+ gncCustomerCommitEdit (customer);
+ do_test (gncCustomerIsDirty (customer), "test dirty after commit");
+ do_test (gnc_numeric_equal (get (customer), num), message);
+ gncCustomerSetActive (customer, FALSE);
+ count++;
}
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncCustomer *, gboolean),
- gboolean (*get) (const GncCustomer *))
+ void (*set) (GncCustomer *, gboolean),
+ gboolean (*get) (const GncCustomer *))
{
- GncCustomer *customer = gncCustomerCreate (book);
- gboolean num = get_random_boolean ();
+ GncCustomer *customer = gncCustomerCreate (book);
+ gboolean num = get_random_boolean ();
- do_test (!gncCustomerIsDirty (customer), "test if start dirty");
- gncCustomerBeginEdit (customer);
- set (customer, FALSE);
- set (customer, TRUE);
- set (customer, num);
- do_test (gncCustomerIsDirty (customer), "test dirty later");
- gncCustomerCommitEdit (customer);
- do_test (gncCustomerIsDirty (customer), "test dirty after commit");
- do_test (get (customer) == num, message);
- gncCustomerSetActive (customer, FALSE);
- count++;
+ do_test (!gncCustomerIsDirty (customer), "test if start dirty");
+ gncCustomerBeginEdit (customer);
+ set (customer, FALSE);
+ set (customer, TRUE);
+ set (customer, num);
+ do_test (gncCustomerIsDirty (customer), "test dirty later");
+ gncCustomerCommitEdit (customer);
+ do_test (gncCustomerIsDirty (customer), "test dirty after commit");
+ do_test (get (customer) == num, message);
+ gncCustomerSetActive (customer, FALSE);
+ count++;
}
int
main (int argc, char **argv)
{
- qof_init();
- do_test (cashobjects_register(), "Cannot register cash objects");
- do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
- do_test (gncJobRegister (), "Cannot register GncJob");
- do_test (gncCustomerRegister(), "Cannot register GncCustomer");
- test_customer();
- print_test_results();
- qof_close ();
- return 0;
+ qof_init();
+ do_test (cashobjects_register(), "Cannot register cash objects");
+ do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
+ do_test (gncJobRegister (), "Cannot register GncJob");
+ do_test (gncCustomerRegister(), "Cannot register GncCustomer");
+ test_customer();
+ print_test_results();
+ qof_close ();
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-employee.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-employee.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-employee.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-employee.c
* Test the employee object (without Guile).
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
* Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
*
@@ -37,194 +37,195 @@
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, const char *str),
- const char * (*get)(const GncEmployee *));
+ void (*set) (GncEmployee *, const char *str),
+ const char * (*get)(const GncEmployee *));
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gnc_numeric),
- gnc_numeric (*get)(const GncEmployee *));
+ void (*set) (GncEmployee *, gnc_numeric),
+ gnc_numeric (*get)(const GncEmployee *));
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gboolean),
- gboolean (*get) (const GncEmployee *));
+ void (*set) (GncEmployee *, gboolean),
+ gboolean (*get) (const GncEmployee *));
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gint),
- gint (*get) (GncEmployee *));
+ void (*set) (GncEmployee *, gint),
+ gint (*get) (GncEmployee *));
#endif
static void
test_employee (void)
{
- QofBackend *be;
- QofBook *book;
- QofSession *session;
- GncEmployee *employee;
+ QofBackend *be;
+ QofBook *book;
+ QofSession *session;
+ GncEmployee *employee;
- session = qof_session_new();
- qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
- book = qof_session_get_book(session);
- /* The book *must* have a backend to pass the test of the 'dirty' flag */
- /* See the README file for details */
-
- be = qof_book_get_backend (book);
+ session = qof_session_new();
+ qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
+ book = qof_session_get_book(session);
+ /* The book *must* have a backend to pass the test of the 'dirty' flag */
+ /* See the README file for details */
- /* Test creation/destruction */
- {
- do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
- employee = gncEmployeeCreate (book);
- do_test (employee != NULL, "employee create");
- do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
- "getbook");
+ be = qof_book_get_backend (book);
- gncEmployeeBeginEdit (employee);
- gncEmployeeDestroy (employee);
- success ("create/destroy");
- }
+ /* Test creation/destruction */
+ {
+ do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
+ employee = gncEmployeeCreate (book);
+ do_test (employee != NULL, "employee create");
+ do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
+ "getbook");
- /* Test setting/getting routines; does the active flag get set right? */
- {
- GUID guid;
+ gncEmployeeBeginEdit (employee);
+ gncEmployeeDestroy (employee);
+ success ("create/destroy");
+ }
- test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
- test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
- test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
- test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);
+ /* Test setting/getting routines; does the active flag get set right? */
+ {
+ GUID guid;
- test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
- test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);
+ test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
+ test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
+ test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
+ test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);
- test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);
+ test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
+ test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);
- do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");
+ test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);
- guid_new (&guid);
- employee = gncEmployeeCreate (book); count++;
- gncEmployeeSetGUID (employee, &guid);
- do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
- }
+ do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");
+
+ guid_new (&guid);
+ employee = gncEmployeeCreate (book);
+ count++;
+ gncEmployeeSetGUID (employee, &guid);
+ do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
+ }
#if 0
- {
- GList *list;
+ {
+ GList *list;
- list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
- do_test (list != NULL, "getList all");
- do_test (g_list_length (list) == count, "correct length: all");
- g_list_free (list);
+ list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
+ do_test (list != NULL, "getList all");
+ do_test (g_list_length (list) == count, "correct length: all");
+ g_list_free (list);
- list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
- do_test (list != NULL, "getList active");
- do_test (g_list_length (list) == 1, "correct length: active");
- g_list_free (list);
- }
+ list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
+ do_test (list != NULL, "getList active");
+ do_test (g_list_length (list) == 1, "correct length: active");
+ g_list_free (list);
+ }
#endif
- {
- const char *str = get_random_string();
- const char *res;
- GncAddress *addr;
+ {
+ const char *str = get_random_string();
+ const char *res;
+ GncAddress *addr;
- addr = gncEmployeeGetAddr (employee);
- gncAddressSetName (addr, str);
- res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
- do_test (res != NULL, "Printable NULL?");
- do_test (safe_strcmp (str, res) == 0, "Printable equals");
- }
+ addr = gncEmployeeGetAddr (employee);
+ gncAddressSetName (addr, str);
+ res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
+ do_test (res != NULL, "Printable NULL?");
+ do_test (safe_strcmp (str, res) == 0, "Printable equals");
+ }
}
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, const char *str),
- const char * (*get)(const GncEmployee *))
+ void (*set) (GncEmployee *, const char *str),
+ const char * (*get)(const GncEmployee *))
{
- GncEmployee *employee = gncEmployeeCreate (book);
- char const *str = get_random_string ();
+ GncEmployee *employee = gncEmployeeCreate (book);
+ char const *str = get_random_string ();
- do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
- gncEmployeeBeginEdit (employee);
- set (employee, str);
- do_test (gncEmployeeIsDirty (employee), "test dirty later");
- gncEmployeeCommitEdit (employee);
- do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
- do_test (safe_strcmp (get (employee), str) == 0, message);
- gncEmployeeSetActive (employee, FALSE);
- count++;
+ do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
+ gncEmployeeBeginEdit (employee);
+ set (employee, str);
+ do_test (gncEmployeeIsDirty (employee), "test dirty later");
+ gncEmployeeCommitEdit (employee);
+ do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
+ do_test (safe_strcmp (get (employee), str) == 0, message);
+ gncEmployeeSetActive (employee, FALSE);
+ count++;
}
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gnc_numeric),
- gnc_numeric (*get)(const GncEmployee *))
+ void (*set) (GncEmployee *, gnc_numeric),
+ gnc_numeric (*get)(const GncEmployee *))
{
- GncEmployee *employee = gncEmployeeCreate (book);
- gnc_numeric num = gnc_numeric_create (17, 1);
+ GncEmployee *employee = gncEmployeeCreate (book);
+ gnc_numeric num = gnc_numeric_create (17, 1);
- do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
- gncEmployeeBeginEdit (employee);
- set (employee, num);
- do_test (gncEmployeeIsDirty (employee), "test dirty later");
- gncEmployeeCommitEdit (employee);
- do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
- do_test (gnc_numeric_equal (get (employee), num), message);
- gncEmployeeSetActive (employee, FALSE);
- count++;
+ do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
+ gncEmployeeBeginEdit (employee);
+ set (employee, num);
+ do_test (gncEmployeeIsDirty (employee), "test dirty later");
+ gncEmployeeCommitEdit (employee);
+ do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
+ do_test (gnc_numeric_equal (get (employee), num), message);
+ gncEmployeeSetActive (employee, FALSE);
+ count++;
}
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gboolean),
- gboolean (*get) (const GncEmployee *))
+ void (*set) (GncEmployee *, gboolean),
+ gboolean (*get) (const GncEmployee *))
{
- GncEmployee *employee = gncEmployeeCreate (book);
- gboolean num = get_random_boolean ();
+ GncEmployee *employee = gncEmployeeCreate (book);
+ gboolean num = get_random_boolean ();
- do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
- gncEmployeeBeginEdit (employee);
- set (employee, FALSE);
- set (employee, TRUE);
- set (employee, num);
- do_test (gncEmployeeIsDirty (employee), "test dirty later");
- gncEmployeeCommitEdit (employee);
- do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
- do_test (get (employee) == num, message);
- gncEmployeeSetActive (employee, FALSE);
- count++;
+ do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
+ gncEmployeeBeginEdit (employee);
+ set (employee, FALSE);
+ set (employee, TRUE);
+ set (employee, num);
+ do_test (gncEmployeeIsDirty (employee), "test dirty later");
+ gncEmployeeCommitEdit (employee);
+ do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
+ do_test (get (employee) == num, message);
+ gncEmployeeSetActive (employee, FALSE);
+ count++;
}
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncEmployee *, gint),
- gint (*get) (GncEmployee *))
+ void (*set) (GncEmployee *, gint),
+ gint (*get) (GncEmployee *))
{
- GncEmployee *employee = gncEmployeeCreate (book);
- gint num = 17;
+ GncEmployee *employee = gncEmployeeCreate (book);
+ gint num = 17;
- do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
- gncEmployeeBeginEdit (employee);
- set (employee, num);
- do_test (gncEmployeeIsDirty (employee), "test dirty later");
- gncEmployeeCommitEdit (employee);
- do_test (!gncEmployeeIsDirty (employee), "test dirty after commit");
- do_test (get (employee) == num, message);
- gncEmployeeSetActive (employee, FALSE);
- count++;
+ do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
+ gncEmployeeBeginEdit (employee);
+ set (employee, num);
+ do_test (gncEmployeeIsDirty (employee), "test dirty later");
+ gncEmployeeCommitEdit (employee);
+ do_test (!gncEmployeeIsDirty (employee), "test dirty after commit");
+ do_test (get (employee) == num, message);
+ gncEmployeeSetActive (employee, FALSE);
+ count++;
}
#endif
int
main (int argc, char **argv)
-{
- qof_init();
- do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
- do_test (gncJobRegister (), "Cannot register GncJob");
- do_test (gncCustomerRegister(), "Cannot register GncCustomer");
- do_test (gncEmployeeRegister(), "Cannot register GncEmployee");
- test_employee();
- print_test_results();
- qof_close();
- return 0;
+{
+ qof_init();
+ do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
+ do_test (gncJobRegister (), "Cannot register GncJob");
+ do_test (gncCustomerRegister(), "Cannot register GncCustomer");
+ do_test (gncEmployeeRegister(), "Cannot register GncEmployee");
+ test_employee();
+ print_test_results();
+ qof_close();
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-job.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-job.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-job.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-job.c
* Test the job object.
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
* Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
*
@@ -37,211 +37,216 @@
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, const char *str),
- const char * (*get)(const GncJob *));
+ void (*set) (GncJob *, const char *str),
+ const char * (*get)(const GncJob *));
#if 0
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gnc_numeric),
- gnc_numeric (*get)(const GncJob *));
+ void (*set) (GncJob *, gnc_numeric),
+ gnc_numeric (*get)(const GncJob *));
#endif
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gboolean),
- gboolean (*get) (const GncJob *));
+ void (*set) (GncJob *, gboolean),
+ gboolean (*get) (const GncJob *));
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gint),
- gint (*get) (const GncJob *));
+ void (*set) (GncJob *, gint),
+ gint (*get) (const GncJob *));
#endif
static void
test_job (void)
{
- QofBackend *be;
- QofSession *session;
- QofBook *book;
- GncJob *job;
+ QofBackend *be;
+ QofSession *session;
+ QofBook *book;
+ GncJob *job;
- session = qof_session_new();
- be = NULL;
- qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
- book = qof_session_get_book (session);
- be = qof_book_get_backend(book);
+ session = qof_session_new();
+ be = NULL;
+ qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
+ book = qof_session_get_book (session);
+ be = qof_book_get_backend(book);
- /* The book *must* have a backend to pass the test of the 'dirty' flag */
- /* See the README file for details */
- do_test (be != NULL, "qsf backend could not be set");
+ /* The book *must* have a backend to pass the test of the 'dirty' flag */
+ /* See the README file for details */
+ do_test (be != NULL, "qsf backend could not be set");
- /* Test creation/destruction */
- {
- do_test (gncJobCreate (NULL) == NULL, "job create NULL");
- job = gncJobCreate (book);
- do_test (job != NULL, "job create");
- do_test (qof_instance_get_book(QOF_INSTANCE(job)) == book,
- "getbook");
+ /* Test creation/destruction */
+ {
+ do_test (gncJobCreate (NULL) == NULL, "job create NULL");
+ job = gncJobCreate (book);
+ do_test (job != NULL, "job create");
+ do_test (qof_instance_get_book(QOF_INSTANCE(job)) == book,
+ "getbook");
- gncJobBeginEdit (job);
- gncJobDestroy (job);
- success ("create/destroy");
- }
+ gncJobBeginEdit (job);
+ gncJobDestroy (job);
+ success ("create/destroy");
+ }
- /* Test setting/getting routines; does the active flag get set right? */
- {
- GUID guid;
+ /* Test setting/getting routines; does the active flag get set right? */
+ {
+ GUID guid;
- test_string_fcn (book, "Id", gncJobSetID, gncJobGetID);
- test_string_fcn (book, "Name", gncJobSetName, gncJobGetName);
- test_string_fcn (book, "Reference", gncJobSetReference, gncJobGetReference);
+ test_string_fcn (book, "Id", gncJobSetID, gncJobGetID);
+ test_string_fcn (book, "Name", gncJobSetName, gncJobGetName);
+ test_string_fcn (book, "Reference", gncJobSetReference, gncJobGetReference);
- test_bool_fcn (book, "Active", gncJobSetActive, gncJobGetActive);
+ test_bool_fcn (book, "Active", gncJobSetActive, gncJobGetActive);
- guid_new (&guid);
- job = gncJobCreate (book); count++;
- gncJobSetGUID (job, &guid);
- do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(job))), "guid compare");
- }
+ guid_new (&guid);
+ job = gncJobCreate (book);
+ count++;
+ gncJobSetGUID (job, &guid);
+ do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(job))), "guid compare");
+ }
#if 0
- {
- GList *list;
+ {
+ GList *list;
- list = gncBusinessGetList (book, GNC_ID_JOB, TRUE);
- do_test (list != NULL, "getList all");
- do_test (g_list_length (list) == count, "correct length: all");
- g_list_free (list);
+ list = gncBusinessGetList (book, GNC_ID_JOB, TRUE);
+ do_test (list != NULL, "getList all");
+ do_test (g_list_length (list) == count, "correct length: all");
+ g_list_free (list);
- list = gncBusinessGetList (book, GNC_ID_JOB, FALSE);
- do_test (list != NULL, "getList active");
- do_test (g_list_length (list) == 1, "correct length: active");
- g_list_free (list);
- }
+ list = gncBusinessGetList (book, GNC_ID_JOB, FALSE);
+ do_test (list != NULL, "getList active");
+ do_test (g_list_length (list) == 1, "correct length: active");
+ g_list_free (list);
+ }
#endif
- {
- const char *str = get_random_string();
- const char *res;
+ {
+ const char *str = get_random_string();
+ const char *res;
- gncJobSetName (job, str);
- res = qof_object_printable (GNC_ID_JOB, job);
- do_test (res != NULL, "Printable NULL?");
- do_test (safe_strcmp (str, res) == 0, "Printable equals");
- }
- {
- GList *list;
- GncOwner owner;
- GncCustomer *cust = gncCustomerCreate (book);
+ gncJobSetName (job, str);
+ res = qof_object_printable (GNC_ID_JOB, job);
+ do_test (res != NULL, "Printable NULL?");
+ do_test (safe_strcmp (str, res) == 0, "Printable equals");
+ }
+ {
+ GList *list;
+ GncOwner owner;
+ GncCustomer *cust = gncCustomerCreate (book);
- gncOwnerInitCustomer (&owner, cust);
+ gncOwnerInitCustomer (&owner, cust);
- do_test (gncCustomerGetJoblist (cust, TRUE) == NULL, "empty list at start");
- gncJobSetOwner (job, &owner);
- list = gncCustomerGetJoblist (cust, FALSE);
- do_test (list != NULL, "added to cust");
- do_test (g_list_length (list) == 1, "correct joblist length");
- do_test (list->data == job, "verify job in list");
- gncJobSetActive (job, FALSE);
- list = gncCustomerGetJoblist (cust, FALSE);
- do_test (list == NULL, "no active jobs");
- list = gncCustomerGetJoblist (cust, TRUE);
- do_test (list != NULL, "all jobs");
- gncJobBeginEdit (job);
- gncJobDestroy (job);
- list = gncCustomerGetJoblist (cust, TRUE);
- do_test (list == NULL, "no more jobs");
- }
+ do_test (gncCustomerGetJoblist (cust, TRUE) == NULL, "empty list at start");
+ gncJobSetOwner (job, &owner);
+ list = gncCustomerGetJoblist (cust, FALSE);
+ do_test (list != NULL, "added to cust");
+ do_test (g_list_length (list) == 1, "correct joblist length");
+ do_test (list->data == job, "verify job in list");
+ gncJobSetActive (job, FALSE);
+ list = gncCustomerGetJoblist (cust, FALSE);
+ do_test (list == NULL, "no active jobs");
+ list = gncCustomerGetJoblist (cust, TRUE);
+ do_test (list != NULL, "all jobs");
+ gncJobBeginEdit (job);
+ gncJobDestroy (job);
+ list = gncCustomerGetJoblist (cust, TRUE);
+ do_test (list == NULL, "no more jobs");
+ }
}
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, const char *str),
- const char * (*get)(const GncJob *))
+ void (*set) (GncJob *, const char *str),
+ const char * (*get)(const GncJob *))
{
- GncJob *job = gncJobCreate (book);
- char const *str = get_random_string ();
+ GncJob *job = gncJobCreate (book);
+ char const *str = get_random_string ();
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
- gncJobBeginEdit (job);
- set (job, str);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
- gncJobCommitEdit (job);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
- do_test (safe_strcmp (get (job), str) == 0, message);
- gncJobSetActive (job, FALSE); count++;
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
+ gncJobBeginEdit (job);
+ set (job, str);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
+ gncJobCommitEdit (job);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
+ do_test (safe_strcmp (get (job), str) == 0, message);
+ gncJobSetActive (job, FALSE);
+ count++;
}
#if 0
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gnc_numeric),
- gnc_numeric (*get)(const GncJob *))
+ void (*set) (GncJob *, gnc_numeric),
+ gnc_numeric (*get)(const GncJob *))
{
- GncJob *job = gncJobCreate (book);
- gnc_numeric num = gnc_numeric_create (17, 1);
+ GncJob *job = gncJobCreate (book);
+ gnc_numeric num = gnc_numeric_create (17, 1);
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
- gncJobBeginEdit (job);
- set (job, num);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
- gncJobCommitEdit (job);
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
- do_test (gnc_numeric_equal (get (job), num), message);
- gncJobSetActive (job, FALSE); count++;
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
+ gncJobBeginEdit (job);
+ set (job, num);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
+ gncJobCommitEdit (job);
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
+ do_test (gnc_numeric_equal (get (job), num), message);
+ gncJobSetActive (job, FALSE);
+ count++;
}
#endif
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gboolean),
- gboolean (*get) (const GncJob *))
+ void (*set) (GncJob *, gboolean),
+ gboolean (*get) (const GncJob *))
{
- GncJob *job = gncJobCreate (book);
- gboolean num = get_random_boolean ();
+ GncJob *job = gncJobCreate (book);
+ gboolean num = get_random_boolean ();
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
- gncJobBeginEdit (job);
- set (job, FALSE);
- set (job, TRUE);
- set (job, num);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
- gncJobCommitEdit (job);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
- do_test (get (job) == num, message);
- gncJobSetActive (job, FALSE); count++;
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
+ gncJobBeginEdit (job);
+ set (job, FALSE);
+ set (job, TRUE);
+ set (job, num);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
+ gncJobCommitEdit (job);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
+ do_test (get (job) == num, message);
+ gncJobSetActive (job, FALSE);
+ count++;
}
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncJob *, gint),
- gint (*get) (const GncJob *))
+ void (*set) (GncJob *, gint),
+ gint (*get) (const GncJob *))
{
- GncJob *job = gncJobCreate (book);
- gint num = 17;
+ GncJob *job = gncJobCreate (book);
+ gint num = 17;
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
- gncJobBeginEdit (job);
- set (job, num);
- do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
- gncJobCommitEdit (job);
- do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
- do_test (get (job) == num, message);
- gncJobSetActive (job, FALSE); count++;
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
+ gncJobBeginEdit (job);
+ set (job, num);
+ do_test (qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty later");
+ gncJobCommitEdit (job);
+ do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
+ do_test (get (job) == num, message);
+ gncJobSetActive (job, FALSE);
+ count++;
}
#endif
int
main (int argc, char **argv)
{
- qof_init();
- do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
- do_test (gncJobRegister (), "Cannot register GncJob");
- do_test (gncCustomerRegister(), "Cannot register GncCustomer");
- test_job();
- print_test_results();
- qof_close();
- return 0;
+ qof_init();
+ do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
+ do_test (gncJobRegister (), "Cannot register GncJob");
+ do_test (gncCustomerRegister(), "Cannot register GncCustomer");
+ test_job();
+ print_test_results();
+ qof_close();
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-load-module.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-load-module.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-load-module.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,6 +1,6 @@
/*********************************************************************
* test-load-module.c
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
*
* This program is free software; you can redistribute it and/or
@@ -31,30 +31,32 @@
static void
guile_main (void *closure, int argc, char ** argv)
{
- GNCModule module;
+ GNCModule module;
- printf(" test-load-module.c: loading/unloading business-core module ... ");
+ printf(" test-load-module.c: loading/unloading business-core module ... ");
- gnc_module_system_init();
- module = gnc_module_load("gnucash/business-core", 0);
-
- if(!module) {
- printf(" Failed to load engine\n");
- exit(-1);
- }
-
- if(!gnc_module_unload(module)) {
- printf(" Failed to unload engine\n");
- exit(-1);
- }
- printf(" successful.\n");
+ gnc_module_system_init();
+ module = gnc_module_load("gnucash/business-core", 0);
- exit(0);
+ if (!module)
+ {
+ printf(" Failed to load engine\n");
+ exit(-1);
+ }
+
+ if (!gnc_module_unload(module))
+ {
+ printf(" Failed to unload engine\n");
+ exit(-1);
+ }
+ printf(" successful.\n");
+
+ exit(0);
}
int
main (int argc, char ** argv)
{
- scm_boot_guile(argc, argv, guile_main, NULL);
- return 0;
+ scm_boot_guile(argc, argv, guile_main, NULL);
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/test/test-vendor.c
===================================================================
--- gnucash/trunk/src/business/business-core/test/test-vendor.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/test/test-vendor.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -1,7 +1,7 @@
/*********************************************************************
* test-vendor.c
* Test the vendor object.
- *
+ *
* Copyright (c) 2001 Derek Atkins <warlord at MIT.EDU>
* Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
*
@@ -36,193 +36,198 @@
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, const char *str),
- const char * (*get)(const GncVendor *));
+ void (*set) (GncVendor *, const char *str),
+ const char * (*get)(const GncVendor *));
#if 0
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gnc_numeric),
- gnc_numeric (*get)(const GncVendor *));
+ void (*set) (GncVendor *, gnc_numeric),
+ gnc_numeric (*get)(const GncVendor *));
#endif
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gboolean),
- gboolean (*get) (const GncVendor *));
+ void (*set) (GncVendor *, gboolean),
+ gboolean (*get) (const GncVendor *));
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gint),
- gint (*get) (const GncVendor *));
+ void (*set) (GncVendor *, gint),
+ gint (*get) (const GncVendor *));
#endif
static void
test_vendor (void)
{
- QofBackend *be;
- QofSession *session;
- QofBook *book;
- GncVendor *vendor;
+ QofBackend *be;
+ QofSession *session;
+ QofBook *book;
+ GncVendor *vendor;
- session = qof_session_new();
- be = NULL;
- qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
- book = qof_session_get_book (session);
- be = qof_book_get_backend(book);
+ session = qof_session_new();
+ be = NULL;
+ qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
+ book = qof_session_get_book (session);
+ be = qof_book_get_backend(book);
- /* The book *must* have a backend to pass the test of the 'dirty' flag */
- /* See the README file for details */
- do_test (be != NULL, "qsf backend could not be set");
+ /* The book *must* have a backend to pass the test of the 'dirty' flag */
+ /* See the README file for details */
+ do_test (be != NULL, "qsf backend could not be set");
- /* Test creation/destruction */
- {
- do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
- vendor = gncVendorCreate (book);
- do_test (vendor != NULL, "vendor create");
- do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
- "getbook");
+ /* Test creation/destruction */
+ {
+ do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
+ vendor = gncVendorCreate (book);
+ do_test (vendor != NULL, "vendor create");
+ do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
+ "getbook");
- gncVendorBeginEdit (vendor);
- gncVendorDestroy (vendor);
- success ("create/destroy");
- }
+ gncVendorBeginEdit (vendor);
+ gncVendorDestroy (vendor);
+ success ("create/destroy");
+ }
- /* Test setting/getting routines; does the active flag get set right? */
- {
- GUID guid;
+ /* Test setting/getting routines; does the active flag get set right? */
+ {
+ GUID guid;
- test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
- test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
- test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);
+ test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
+ test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
+ test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);
- //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
+ //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);
- //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
- test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);
+ //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
+ test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);
- do_test (gncVendorGetAddr (vendor) != NULL, "Addr");
+ do_test (gncVendorGetAddr (vendor) != NULL, "Addr");
- guid_new (&guid);
- vendor = gncVendorCreate (book); count++;
- gncVendorSetGUID (vendor, &guid);
- do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
- }
+ guid_new (&guid);
+ vendor = gncVendorCreate (book);
+ count++;
+ gncVendorSetGUID (vendor, &guid);
+ do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
+ }
#if 0
- {
- GList *list;
+ {
+ GList *list;
- list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
- do_test (list != NULL, "getList all");
- do_test (g_list_length (list) == count, "correct length: all");
- g_list_free (list);
+ list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
+ do_test (list != NULL, "getList all");
+ do_test (g_list_length (list) == count, "correct length: all");
+ g_list_free (list);
- list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
- do_test (list != NULL, "getList active");
- do_test (g_list_length (list) == 1, "correct length: active");
- g_list_free (list);
- }
+ list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
+ do_test (list != NULL, "getList active");
+ do_test (g_list_length (list) == 1, "correct length: active");
+ g_list_free (list);
+ }
#endif
- {
- const char *str = get_random_string();
- const char *res;
+ {
+ const char *str = get_random_string();
+ const char *res;
- gncVendorSetName (vendor, str);
- res = qof_object_printable (GNC_ID_VENDOR, vendor);
- do_test (res != NULL, "Printable NULL?");
- do_test (safe_strcmp (str, res) == 0, "Printable equals");
- }
+ gncVendorSetName (vendor, str);
+ res = qof_object_printable (GNC_ID_VENDOR, vendor);
+ do_test (res != NULL, "Printable NULL?");
+ do_test (safe_strcmp (str, res) == 0, "Printable equals");
+ }
}
static void
test_string_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, const char *str),
- const char * (*get)(const GncVendor *))
+ void (*set) (GncVendor *, const char *str),
+ const char * (*get)(const GncVendor *))
{
- GncVendor *vendor = gncVendorCreate (book);
- char const *str = get_random_string ();
+ GncVendor *vendor = gncVendorCreate (book);
+ char const *str = get_random_string ();
- do_test (!gncVendorIsDirty (vendor), "test if start dirty");
- gncVendorBeginEdit (vendor);
- set (vendor, str);
- do_test (gncVendorIsDirty (vendor), "test dirty later");
- gncVendorCommitEdit (vendor);
- do_test (gncVendorIsDirty (vendor), "test dirty after commit");
- do_test (safe_strcmp (get (vendor), str) == 0, message);
- gncVendorSetActive (vendor, FALSE); count++;
+ do_test (!gncVendorIsDirty (vendor), "test if start dirty");
+ gncVendorBeginEdit (vendor);
+ set (vendor, str);
+ do_test (gncVendorIsDirty (vendor), "test dirty later");
+ gncVendorCommitEdit (vendor);
+ do_test (gncVendorIsDirty (vendor), "test dirty after commit");
+ do_test (safe_strcmp (get (vendor), str) == 0, message);
+ gncVendorSetActive (vendor, FALSE);
+ count++;
}
#if 0
static void
test_numeric_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gnc_numeric),
- gnc_numeric (*get)(const GncVendor *))
+ void (*set) (GncVendor *, gnc_numeric),
+ gnc_numeric (*get)(const GncVendor *))
{
- GncVendor *vendor = gncVendorCreate (book);
- gnc_numeric num = gnc_numeric_create (17, 1);
+ GncVendor *vendor = gncVendorCreate (book);
+ gnc_numeric num = gnc_numeric_create (17, 1);
- do_test (!gncVendorIsDirty (vendor), "test if start dirty");
- gncVendoryBeginEdit (vendor);
- set (vendor, num);
- do_test (gncVendorIsDirty (vendor), "test dirty later");
- gncVendorCommitEdit (vendor);
- do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
- do_test (gnc_numeric_equal (get (vendor), num), message);
- gncVendorSetActive (vendor, FALSE); count++;
+ do_test (!gncVendorIsDirty (vendor), "test if start dirty");
+ gncVendoryBeginEdit (vendor);
+ set (vendor, num);
+ do_test (gncVendorIsDirty (vendor), "test dirty later");
+ gncVendorCommitEdit (vendor);
+ do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
+ do_test (gnc_numeric_equal (get (vendor), num), message);
+ gncVendorSetActive (vendor, FALSE);
+ count++;
}
#endif
static void
test_bool_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gboolean),
- gboolean (*get) (const GncVendor *))
+ void (*set) (GncVendor *, gboolean),
+ gboolean (*get) (const GncVendor *))
{
- GncVendor *vendor = gncVendorCreate (book);
- gboolean num = get_random_boolean ();
+ GncVendor *vendor = gncVendorCreate (book);
+ gboolean num = get_random_boolean ();
- do_test (!gncVendorIsDirty (vendor), "test if start dirty");
- gncVendorBeginEdit (vendor);
- set (vendor, FALSE);
- set (vendor, TRUE);
- set (vendor, num);
- do_test (gncVendorIsDirty (vendor), "test dirty later");
- gncVendorCommitEdit (vendor);
- do_test (gncVendorIsDirty (vendor), "test dirty after commit");
- do_test (get (vendor) == num, message);
- gncVendorSetActive (vendor, FALSE); count++;
+ do_test (!gncVendorIsDirty (vendor), "test if start dirty");
+ gncVendorBeginEdit (vendor);
+ set (vendor, FALSE);
+ set (vendor, TRUE);
+ set (vendor, num);
+ do_test (gncVendorIsDirty (vendor), "test dirty later");
+ gncVendorCommitEdit (vendor);
+ do_test (gncVendorIsDirty (vendor), "test dirty after commit");
+ do_test (get (vendor) == num, message);
+ gncVendorSetActive (vendor, FALSE);
+ count++;
}
#if 0
static void
test_gint_fcn (QofBook *book, const char *message,
- void (*set) (GncVendor *, gint),
- gint (*get) (const GncVendor *))
+ void (*set) (GncVendor *, gint),
+ gint (*get) (const GncVendor *))
{
- GncVendor *vendor = gncVendorCreate (book);
- gint num = 17;
+ GncVendor *vendor = gncVendorCreate (book);
+ gint num = 17;
- do_test (!gncVendorIsDirty (vendor), "test if start dirty");
- gncVendorBeginEdit (vendor);
- set (vendor, num);
- do_test (gncVendorIsDirty (vendor), "test dirty later");
- gncVendorCommitEdit (vendor);
- do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
- do_test (get (vendor) == num, message);
- gncVendorSetActive (vendor, FALSE); count++;
+ do_test (!gncVendorIsDirty (vendor), "test if start dirty");
+ gncVendorBeginEdit (vendor);
+ set (vendor, num);
+ do_test (gncVendorIsDirty (vendor), "test dirty later");
+ gncVendorCommitEdit (vendor);
+ do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
+ do_test (get (vendor) == num, message);
+ gncVendorSetActive (vendor, FALSE);
+ count++;
}
#endif
int
main (int argc, char **argv)
{
- qof_init();
- do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
- do_test (gncJobRegister (), "Cannot register GncJob");
- do_test (gncCustomerRegister(), "Cannot register GncCustomer");
- do_test (gncVendorRegister(), "Cannot register GncVendor");
- test_vendor();
- print_test_results();
- qof_close();
- return 0;
+ qof_init();
+ do_test (gncInvoiceRegister(), "Cannot register GncInvoice");
+ do_test (gncJobRegister (), "Cannot register GncJob");
+ do_test (gncCustomerRegister(), "Cannot register GncCustomer");
+ do_test (gncVendorRegister(), "Cannot register GncVendor");
+ test_vendor();
+ print_test_results();
+ qof_close();
+ return 0;
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-address-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-address-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-address-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -61,8 +61,8 @@
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
xmlNodePtr
@@ -74,7 +74,7 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST address_version_string);
maybe_add_string (ret, addr_name_string, gncAddressGetName (addr));
-
+
maybe_add_string (ret, addr_addr1_string, gncAddressGetAddr1 (addr));
maybe_add_string (ret, addr_addr2_string, gncAddressGetAddr2 (addr));
maybe_add_string (ret, addr_addr3_string, gncAddressGetAddr3 (addr));
@@ -91,7 +91,7 @@
struct address_pdata
{
- GncAddress *address;
+ GncAddress *address;
};
static gboolean
@@ -100,11 +100,11 @@
{
gchar* txt = dom_tree_to_text(node);
g_return_val_if_fail(txt, FALSE);
-
+
func(addr, txt);
g_free(txt);
-
+
return TRUE;
}
@@ -175,10 +175,11 @@
static gboolean
address_slots_handler (xmlNodePtr node, gpointer addr_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler address_handlers_v2[] = {
+static struct dom_tree_handler address_handlers_v2[] =
+{
{ addr_name_string, address_name_handler, 0, 0 },
{ addr_addr1_string, address_addr1_handler, 0, 0 },
{ addr_addr2_string, address_addr2_handler, 0, 0 },
@@ -220,18 +221,19 @@
void
gnc_address_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- "gnc:Address",
- NULL, /* parser_create */
- NULL, /* add_item */
- NULL, /* get_count */
- NULL, /* write */
- NULL, /* scrub */
- address_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ "gnc:Address",
+ NULL, /* parser_create */
+ NULL, /* add_item */
+ NULL, /* get_count */
+ NULL, /* write */
+ NULL, /* scrub */
+ address_ns,
+ };
- qof_object_register_backend ("gnc:Address",
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend ("gnc:Address",
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-bill-term-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-bill-term-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-bill-term-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -86,47 +86,48 @@
maybe_add_guid(ret, billterm_guid_string, QOF_INSTANCE(term));
xmlAddChild(ret, text_to_dom_tree (billterm_name_string,
- gncBillTermGetName (term)));
+ gncBillTermGetName (term)));
xmlAddChild(ret, text_to_dom_tree (billterm_desc_string,
- gncBillTermGetDescription (term)));
+ gncBillTermGetDescription (term)));
xmlAddChild(ret, int_to_dom_tree (billterm_refcount_string,
- gncBillTermGetRefcount (term)));
+ gncBillTermGetRefcount (term)));
xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string,
- gncBillTermGetInvisible (term)));
+ gncBillTermGetInvisible (term)));
kvpnode = kvp_frame_to_dom_tree (billterm_slots_string,
- qof_instance_get_slots (QOF_INSTANCE(term)));
+ qof_instance_get_slots (QOF_INSTANCE(term)));
if (kvpnode) xmlAddChild (ret, kvpnode);
/* We should not be our own child */
if (gncBillTermGetChild(term) != term)
- maybe_add_guid(ret, billterm_child_string,
- QOF_INSTANCE(gncBillTermGetChild (term)));
+ maybe_add_guid(ret, billterm_child_string,
+ QOF_INSTANCE(gncBillTermGetChild (term)));
maybe_add_guid(ret, billterm_parent_string,
- QOF_INSTANCE(gncBillTermGetParent (term)));
+ QOF_INSTANCE(gncBillTermGetParent (term)));
- switch (gncBillTermGetType (term)) {
+ switch (gncBillTermGetType (term))
+ {
case GNC_TERM_TYPE_DAYS:
- data = xmlNewChild (ret, NULL, BAD_CAST gnc_daystype_string, NULL);
- maybe_add_int (data, days_duedays_string, gncBillTermGetDueDays (term));
- maybe_add_int (data, days_discdays_string,
- gncBillTermGetDiscountDays (term));
- maybe_add_numeric (data, days_discount_string,
- gncBillTermGetDiscount (term));
- break;
+ data = xmlNewChild (ret, NULL, BAD_CAST gnc_daystype_string, NULL);
+ maybe_add_int (data, days_duedays_string, gncBillTermGetDueDays (term));
+ maybe_add_int (data, days_discdays_string,
+ gncBillTermGetDiscountDays (term));
+ maybe_add_numeric (data, days_discount_string,
+ gncBillTermGetDiscount (term));
+ break;
case GNC_TERM_TYPE_PROXIMO:
- data = xmlNewChild (ret, NULL, BAD_CAST gnc_proximotype_string, NULL);
- maybe_add_int (data, prox_dueday_string, gncBillTermGetDueDays (term));
- maybe_add_int (data, prox_discday_string,
- gncBillTermGetDiscountDays (term));
- maybe_add_numeric (data, prox_discount_string,
- gncBillTermGetDiscount (term));
- maybe_add_int (data, prox_cutoff_string, gncBillTermGetCutoff (term));
- break;
+ data = xmlNewChild (ret, NULL, BAD_CAST gnc_proximotype_string, NULL);
+ maybe_add_int (data, prox_dueday_string, gncBillTermGetDueDays (term));
+ maybe_add_int (data, prox_discday_string,
+ gncBillTermGetDiscountDays (term));
+ maybe_add_numeric (data, prox_discount_string,
+ gncBillTermGetDiscount (term));
+ maybe_add_int (data, prox_cutoff_string, gncBillTermGetCutoff (term));
+ break;
}
return ret;
@@ -136,30 +137,30 @@
struct billterm_pdata
{
- GncBillTerm *term;
- QofBook *book;
+ GncBillTerm *term;
+ QofBook *book;
};
static gboolean
set_int (xmlNodePtr node, GncBillTerm *term,
- void (*func)(GncBillTerm *, gint))
+ void (*func)(GncBillTerm *, gint))
{
- gint64 val;
- dom_tree_to_integer (node, &val);
- func (term, val);
- return TRUE;
+ gint64 val;
+ dom_tree_to_integer (node, &val);
+ func (term, val);
+ return TRUE;
}
static gboolean
set_numeric (xmlNodePtr node, GncBillTerm *term,
- void (*func)(GncBillTerm *, gnc_numeric))
+ void (*func)(GncBillTerm *, gnc_numeric))
{
- gnc_numeric* num = dom_tree_to_gnc_numeric (node);
- g_return_val_if_fail (num, FALSE);
-
- func (term, *num);
- g_free (num);
- return TRUE;
+ gnc_numeric* num = dom_tree_to_gnc_numeric (node);
+ g_return_val_if_fail (num, FALSE);
+
+ func (term, *num);
+ g_free (num);
+ return TRUE;
}
/***********************************************************************/
@@ -167,42 +168,43 @@
static gboolean
days_duedays_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_int (node, pdata->term, gncBillTermSetDueDays);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_int (node, pdata->term, gncBillTermSetDueDays);
}
static gboolean
days_discdays_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_int (node, pdata->term, gncBillTermSetDiscountDays);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_int (node, pdata->term, gncBillTermSetDiscountDays);
}
static gboolean
days_discount_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_numeric (node, pdata->term, gncBillTermSetDiscount);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_numeric (node, pdata->term, gncBillTermSetDiscount);
}
-static struct dom_tree_handler days_data_handlers_v2[] = {
- { days_duedays_string, days_duedays_handler, 0, 0 },
- { days_discdays_string, days_discdays_handler, 0, 0 },
- { days_discount_string, days_discount_handler, 0, 0 },
- { NULL, 0, 0, 0 }
+static struct dom_tree_handler days_data_handlers_v2[] =
+{
+ { days_duedays_string, days_duedays_handler, 0, 0 },
+ { days_discdays_string, days_discdays_handler, 0, 0 },
+ { days_discount_string, days_discount_handler, 0, 0 },
+ { NULL, 0, 0, 0 }
};
static gboolean
dom_tree_to_days_data (xmlNodePtr node, struct billterm_pdata *pdata)
{
- gboolean successful;
-
- successful = dom_tree_generic_parse (node, days_data_handlers_v2, pdata);
+ gboolean successful;
- if (!successful)
- PERR ("failed to parse billing term days data");
+ successful = dom_tree_generic_parse (node, days_data_handlers_v2, pdata);
- return successful;
+ if (!successful)
+ PERR ("failed to parse billing term days data");
+
+ return successful;
}
/***********************************************************************/
@@ -210,86 +212,88 @@
static gboolean
prox_dueday_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_int (node, pdata->term, gncBillTermSetDueDays);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_int (node, pdata->term, gncBillTermSetDueDays);
}
static gboolean
prox_discday_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_int (node, pdata->term, gncBillTermSetDiscountDays);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_int (node, pdata->term, gncBillTermSetDiscountDays);
}
static gboolean
prox_discount_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_numeric (node, pdata->term, gncBillTermSetDiscount);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_numeric (node, pdata->term, gncBillTermSetDiscount);
}
static gboolean
prox_cutoff_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_int (node, pdata->term, gncBillTermSetCutoff);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_int (node, pdata->term, gncBillTermSetCutoff);
}
-static struct dom_tree_handler prox_data_handlers_v2[] = {
- { prox_dueday_string, prox_dueday_handler, 0, 0 },
- { prox_discday_string, prox_discday_handler, 0, 0 },
- { prox_discount_string, prox_discount_handler, 0, 0 },
- { prox_cutoff_string, prox_cutoff_handler, 0, 0 },
- { NULL, 0, 0, 0 }
+static struct dom_tree_handler prox_data_handlers_v2[] =
+{
+ { prox_dueday_string, prox_dueday_handler, 0, 0 },
+ { prox_discday_string, prox_discday_handler, 0, 0 },
+ { prox_discount_string, prox_discount_handler, 0, 0 },
+ { prox_cutoff_string, prox_cutoff_handler, 0, 0 },
+ { NULL, 0, 0, 0 }
};
static gboolean
dom_tree_to_prox_data (xmlNodePtr node, struct billterm_pdata *pdata)
{
- gboolean successful;
-
- successful = dom_tree_generic_parse (node, prox_data_handlers_v2, pdata);
+ gboolean successful;
- if (!successful)
- PERR ("failed to parse billing term prox data");
+ successful = dom_tree_generic_parse (node, prox_data_handlers_v2, pdata);
- return successful;
+ if (!successful)
+ PERR ("failed to parse billing term prox data");
+
+ return successful;
}
/***********************************************************************/
static gboolean
set_parent_child (xmlNodePtr node, struct billterm_pdata *pdata,
- void (*func)(GncBillTerm *, GncBillTerm *))
+ void (*func)(GncBillTerm *, GncBillTerm *))
{
- GUID *guid;
- GncBillTerm *term;
+ GUID *guid;
+ GncBillTerm *term;
- guid = dom_tree_to_guid(node);
- g_return_val_if_fail (guid, FALSE);
- term = gncBillTermLookup (pdata->book, guid);
- if (!term) {
- term = gncBillTermCreate (pdata->book);
- gncBillTermBeginEdit (term);
- gncBillTermSetGUID (term, guid);
- gncBillTermCommitEdit (term);
- }
- g_free (guid);
- g_return_val_if_fail (term, FALSE);
- func (pdata->term, term);
+ guid = dom_tree_to_guid(node);
+ g_return_val_if_fail (guid, FALSE);
+ term = gncBillTermLookup (pdata->book, guid);
+ if (!term)
+ {
+ term = gncBillTermCreate (pdata->book);
+ gncBillTermBeginEdit (term);
+ gncBillTermSetGUID (term, guid);
+ gncBillTermCommitEdit (term);
+ }
+ g_free (guid);
+ g_return_val_if_fail (term, FALSE);
+ func (pdata->term, term);
- return TRUE;
+ return TRUE;
}
static gboolean
set_string (xmlNodePtr node, GncBillTerm *term,
- void (*func)(GncBillTerm *, const char *))
+ void (*func)(GncBillTerm *, const char *))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
- func (term, txt);
- g_free(txt);
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+ func (term, txt);
+ g_free(txt);
+ return TRUE;
}
static gboolean
@@ -302,103 +306,107 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid);
- if (term) {
- gncBillTermDestroy (pdata->term);
- pdata->term = term;
- gncBillTermBeginEdit (term);
- } else {
- gncBillTermSetGUID(pdata->term, guid);
+ if (term)
+ {
+ gncBillTermDestroy (pdata->term);
+ pdata->term = term;
+ gncBillTermBeginEdit (term);
}
+ else
+ {
+ gncBillTermSetGUID(pdata->term, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
static gboolean
billterm_name_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_string (node, pdata->term, gncBillTermSetName);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_string (node, pdata->term, gncBillTermSetName);
}
static gboolean
billterm_desc_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_string (node, pdata->term, gncBillTermSetDescription);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_string (node, pdata->term, gncBillTermSetDescription);
}
static gboolean
billterm_refcount_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- gint64 val;
+ struct billterm_pdata *pdata = billterm_pdata;
+ gint64 val;
- dom_tree_to_integer(node, &val);
- gncBillTermSetRefcount (pdata->term, val);
- return TRUE;
+ dom_tree_to_integer(node, &val);
+ gncBillTermSetRefcount (pdata->term, val);
+ return TRUE;
}
static gboolean
billterm_invisible_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- gint64 val;
+ struct billterm_pdata *pdata = billterm_pdata;
+ gint64 val;
- dom_tree_to_integer(node, &val);
- if (val)
- gncBillTermMakeInvisible (pdata->term);
- return TRUE;
+ dom_tree_to_integer(node, &val);
+ if (val)
+ gncBillTermMakeInvisible (pdata->term);
+ return TRUE;
}
static gboolean
billterm_parent_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_parent_child (node, pdata, gncBillTermSetParent);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_parent_child (node, pdata, gncBillTermSetParent);
}
static gboolean
billterm_child_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return set_parent_child (node, pdata, gncBillTermSetChild);
+ struct billterm_pdata *pdata = billterm_pdata;
+ return set_parent_child (node, pdata, gncBillTermSetChild);
}
static gboolean
billterm_days_data_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
+ struct billterm_pdata *pdata = billterm_pdata;
- g_return_val_if_fail (node, FALSE);
- g_return_val_if_fail (gncBillTermGetType (pdata->term) == 0, FALSE);
+ g_return_val_if_fail (node, FALSE);
+ g_return_val_if_fail (gncBillTermGetType (pdata->term) == 0, FALSE);
- gncBillTermSetType (pdata->term, GNC_TERM_TYPE_DAYS);
- return dom_tree_to_days_data (node, pdata);
+ gncBillTermSetType (pdata->term, GNC_TERM_TYPE_DAYS);
+ return dom_tree_to_days_data (node, pdata);
}
static gboolean
billterm_prox_data_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
+ struct billterm_pdata *pdata = billterm_pdata;
- g_return_val_if_fail (node, FALSE);
- g_return_val_if_fail (gncBillTermGetType (pdata->term) == 0, FALSE);
+ g_return_val_if_fail (node, FALSE);
+ g_return_val_if_fail (gncBillTermGetType (pdata->term) == 0, FALSE);
- gncBillTermSetType (pdata->term, GNC_TERM_TYPE_PROXIMO);
- return dom_tree_to_prox_data (node, pdata);
+ gncBillTermSetType (pdata->term, GNC_TERM_TYPE_PROXIMO);
+ return dom_tree_to_prox_data (node, pdata);
}
static gboolean
billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata)
{
- struct billterm_pdata *pdata = billterm_pdata;
- return dom_tree_to_kvp_frame_given (node,
- qof_instance_get_slots (QOF_INSTANCE(pdata->term)));
+ struct billterm_pdata *pdata = billterm_pdata;
+ return dom_tree_to_kvp_frame_given (node,
+ qof_instance_get_slots (QOF_INSTANCE(pdata->term)));
}
-static struct dom_tree_handler billterm_handlers_v2[] = {
+static struct dom_tree_handler billterm_handlers_v2[] =
+{
{ billterm_guid_string, billterm_guid_handler, 1, 0 },
{ billterm_name_string, billterm_name_handler, 1, 0 },
{ billterm_desc_string, billterm_desc_handler, 1, 0 },
@@ -415,32 +423,35 @@
static GncBillTerm*
dom_tree_to_billterm (xmlNodePtr node, QofBook *book)
{
- struct billterm_pdata billterm_pdata;
- gboolean successful;
-
- billterm_pdata.term = gncBillTermCreate (book);
- billterm_pdata.book = book;
- gncBillTermBeginEdit (billterm_pdata.term);
+ struct billterm_pdata billterm_pdata;
+ gboolean successful;
- successful = dom_tree_generic_parse (node, billterm_handlers_v2,
- &billterm_pdata);
+ billterm_pdata.term = gncBillTermCreate (book);
+ billterm_pdata.book = book;
+ gncBillTermBeginEdit (billterm_pdata.term);
- if (successful) {
- gncBillTermCommitEdit (billterm_pdata.term);
- } else {
- PERR ("failed to parse billing term tree");
- gncBillTermDestroy (billterm_pdata.term);
- billterm_pdata.term = NULL;
- }
+ successful = dom_tree_generic_parse (node, billterm_handlers_v2,
+ &billterm_pdata);
- return billterm_pdata.term;
+ if (successful)
+ {
+ gncBillTermCommitEdit (billterm_pdata.term);
+ }
+ else
+ {
+ PERR ("failed to parse billing term tree");
+ gncBillTermDestroy (billterm_pdata.term);
+ billterm_pdata.term = NULL;
+ }
+
+ return billterm_pdata.term;
}
static gboolean
gnc_billterm_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncBillTerm *term;
@@ -450,14 +461,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -465,7 +476,7 @@
g_return_val_if_fail(tree, FALSE);
term = dom_tree_to_billterm (tree, book);
- if(term != NULL)
+ if (term != NULL)
{
gdata->cb(tag, gdata->parsedata, term);
}
@@ -478,117 +489,125 @@
static sixtp *
billterm_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_billterm_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_billterm_end_handler, NULL, NULL);
}
static void
do_count (QofInstance *term_p, gpointer count_p)
{
- int *count = count_p;
- (*count)++;
+ int *count = count_p;
+ (*count)++;
}
static int
billterm_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_billterm (QofInstance *term_p, gpointer out_p)
{
- xmlNodePtr node;
- GncBillTerm *term = (GncBillTerm *) term_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncBillTerm *term = (GncBillTerm *) term_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
+ if (ferror(out))
+ return;
- node = billterm_dom_tree_create (term);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = billterm_dom_tree_create (term);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
billterm_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
billterm_is_grandchild (GncBillTerm *term)
{
- return (gncBillTermGetParent(gncBillTermGetParent(term)) != NULL);
+ return (gncBillTermGetParent(gncBillTermGetParent(term)) != NULL);
}
static GncBillTerm *
billterm_find_senior (GncBillTerm *term)
{
- GncBillTerm *temp, *parent, *gp = NULL;
+ GncBillTerm *temp, *parent, *gp = NULL;
- temp = term;
- do {
- /* See if "temp" is a grandchild */
- parent = gncBillTermGetParent(temp);
- if (!parent)
- break;
- gp = gncBillTermGetParent(parent);
- if (!gp)
- break;
+ temp = term;
+ do
+ {
+ /* See if "temp" is a grandchild */
+ parent = gncBillTermGetParent(temp);
+ if (!parent)
+ break;
+ gp = gncBillTermGetParent(parent);
+ if (!gp)
+ break;
- /* Yep, this is a grandchild. Move up one generation and try again */
- temp = parent;
- } while (TRUE);
+ /* Yep, this is a grandchild. Move up one generation and try again */
+ temp = parent;
+ }
+ while (TRUE);
- /* Ok, at this point temp points to the most senior child and parent
- * should point to the top billterm (and gp should be NULL). If
- * parent is NULL then we are the most senior child (and have no
- * children), so do nothing. If temp == term then there is no
- * grandparent, so do nothing.
- *
- * Do something if parent != NULL && temp != term
- */
- g_assert (gp == NULL);
+ /* Ok, at this point temp points to the most senior child and parent
+ * should point to the top billterm (and gp should be NULL). If
+ * parent is NULL then we are the most senior child (and have no
+ * children), so do nothing. If temp == term then there is no
+ * grandparent, so do nothing.
+ *
+ * Do something if parent != NULL && temp != term
+ */
+ g_assert (gp == NULL);
- /* return the most senior term */
- return temp;
+ /* return the most senior term */
+ return temp;
}
/* build a list of bill terms that are grandchildren or bogus (empty entry list). */
static void
billterm_scrub_cb (QofInstance *term_p, gpointer list_p)
{
- GncBillTerm *term = GNC_BILLTERM(term_p);
- GList **list = list_p;
+ GncBillTerm *term = GNC_BILLTERM(term_p);
+ GList **list = list_p;
- if (billterm_is_grandchild(term)) {
- *list = g_list_prepend(*list, term);
+ if (billterm_is_grandchild(term))
+ {
+ *list = g_list_prepend(*list, term);
- } else if (!gncBillTermGetType(term)) {
- GncBillTerm *t = gncBillTermGetParent(term);
- if (t) {
- /* Fix up the broken "copy" function */
- PWARN("Fixing broken child billterm: %s",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
+ }
+ else if (!gncBillTermGetType(term))
+ {
+ GncBillTerm *t = gncBillTermGetParent(term);
+ if (t)
+ {
+ /* Fix up the broken "copy" function */
+ PWARN("Fixing broken child billterm: %s",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
- gncBillTermBeginEdit(term);
- gncBillTermSetType(term, gncBillTermGetType(t));
- gncBillTermSetDueDays (term, gncBillTermGetDueDays(t));
- gncBillTermSetDiscountDays (term, gncBillTermGetDiscountDays(t));
- gncBillTermSetDiscount (term, gncBillTermGetDiscount(t));
- gncBillTermSetCutoff (term, gncBillTermGetCutoff(t));
- gncBillTermCommitEdit(term);
+ gncBillTermBeginEdit(term);
+ gncBillTermSetType(term, gncBillTermGetType(t));
+ gncBillTermSetDueDays (term, gncBillTermGetDueDays(t));
+ gncBillTermSetDiscountDays (term, gncBillTermGetDiscountDays(t));
+ gncBillTermSetDiscount (term, gncBillTermGetDiscount(t));
+ gncBillTermSetCutoff (term, gncBillTermGetCutoff(t));
+ gncBillTermCommitEdit(term);
- } else {
- /* No parent? Must be a standalone */
- *list = g_list_prepend(*list, term);
+ }
+ else
+ {
+ /* No parent? Must be a standalone */
+ *list = g_list_prepend(*list, term);
+ }
}
- }
}
/* for each invoice, check the bill terms. If the bill terms are
@@ -597,167 +616,177 @@
static void
billterm_scrub_invoices (QofInstance * invoice_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncInvoice *invoice = GNC_INVOICE(invoice_p);
- GncBillTerm *term, *new_bt;
- gint32 count;
+ GHashTable *ht = ht_p;
+ GncInvoice *invoice = GNC_INVOICE(invoice_p);
+ GncBillTerm *term, *new_bt;
+ gint32 count;
- term = gncInvoiceGetTerms(invoice);
- if (term) {
- if (billterm_is_grandchild(term)) {
- PWARN("Fixing i-billterm on invoice %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(invoice))));
- new_bt = billterm_find_senior(term);
- gncInvoiceBeginEdit(invoice);
- gncInvoiceSetTerms(invoice, new_bt);
- gncInvoiceCommitEdit(invoice);
- term = new_bt;
+ term = gncInvoiceGetTerms(invoice);
+ if (term)
+ {
+ if (billterm_is_grandchild(term))
+ {
+ PWARN("Fixing i-billterm on invoice %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(invoice))));
+ new_bt = billterm_find_senior(term);
+ gncInvoiceBeginEdit(invoice);
+ gncInvoiceSetTerms(invoice, new_bt);
+ gncInvoiceCommitEdit(invoice);
+ term = new_bt;
+ }
+ if (term)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
+ count++;
+ g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
+ }
}
- if (term) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
- count++;
- g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
- }
- }
}
static void
billterm_scrub_cust (QofInstance * cust_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncCustomer *cust = GNC_CUSTOMER(cust_p);
- GncBillTerm *term;
- gint32 count;
-
- term = gncCustomerGetTerms(cust);
- if (term) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
- count++;
- g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
- if (billterm_is_grandchild(term))
- PWARN("customer %s has grandchild billterm %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(cust))),
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
- }
+ GHashTable *ht = ht_p;
+ GncCustomer *cust = GNC_CUSTOMER(cust_p);
+ GncBillTerm *term;
+ gint32 count;
+
+ term = gncCustomerGetTerms(cust);
+ if (term)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
+ count++;
+ g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
+ if (billterm_is_grandchild(term))
+ PWARN("customer %s has grandchild billterm %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(cust))),
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
+ }
}
static void
billterm_scrub_vendor (QofInstance * vendor_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncVendor *vendor = GNC_VENDOR(vendor_p);
- GncBillTerm *term;
- gint32 count;
+ GHashTable *ht = ht_p;
+ GncVendor *vendor = GNC_VENDOR(vendor_p);
+ GncBillTerm *term;
+ gint32 count;
- term = gncVendorGetTerms(vendor);
- if (term) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
- count++;
- g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
- if (billterm_is_grandchild(term))
- PWARN("vendor %s has grandchild billterm %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))),
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
- }
+ term = gncVendorGetTerms(vendor);
+ if (term)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
+ count++;
+ g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
+ if (billterm_is_grandchild(term))
+ PWARN("vendor %s has grandchild billterm %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))),
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
+ }
}
static void
billterm_reset_refcount (gpointer key, gpointer value, gpointer notused)
{
- GncBillTerm *term = key;
- gint32 count = GPOINTER_TO_INT(value);
+ GncBillTerm *term = key;
+ gint32 count = GPOINTER_TO_INT(value);
- if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term)) {
- PWARN("Fixing refcount on billterm %s (%" G_GINT64_FORMAT " -> %d)\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))),
- gncBillTermGetRefcount(term), count);
- gncBillTermSetRefcount(term, count);
- }
+ if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term))
+ {
+ PWARN("Fixing refcount on billterm %s (%" G_GINT64_FORMAT " -> %d)\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))),
+ gncBillTermGetRefcount(term), count);
+ gncBillTermSetRefcount(term, count);
+ }
}
static void
billterm_scrub (QofBook *book)
{
- GList *list = NULL;
- GList *node;
- GncBillTerm *parent, *term;
- GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
+ GList *list = NULL;
+ GList *node;
+ GncBillTerm *parent, *term;
+ GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
- DEBUG("scrubbing billterms...");
- qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht);
- qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht);
- qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht);
- qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list);
+ DEBUG("scrubbing billterms...");
+ qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht);
+ qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht);
+ qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht);
+ qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list);
- /* destroy the list of "grandchildren" bill terms */
- for (node = list; node; node = node->next) {
- term = node->data;
+ /* destroy the list of "grandchildren" bill terms */
+ for (node = list; node; node = node->next)
+ {
+ term = node->data;
- PWARN ("deleting grandchild billterm: %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
+ PWARN ("deleting grandchild billterm: %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
- /* Make sure the parent has no children */
- parent = gncBillTermGetParent(term);
- gncBillTermSetChild(parent, NULL);
+ /* Make sure the parent has no children */
+ parent = gncBillTermGetParent(term);
+ gncBillTermSetChild(parent, NULL);
- /* Destroy this bill term */
- gncBillTermBeginEdit(term);
- gncBillTermDestroy(term);
- }
+ /* Destroy this bill term */
+ gncBillTermBeginEdit(term);
+ gncBillTermDestroy(term);
+ }
- /* reset the refcounts as necessary */
- g_hash_table_foreach(ht, billterm_reset_refcount, NULL);
+ /* reset the refcounts as necessary */
+ g_hash_table_foreach(ht, billterm_reset_refcount, NULL);
- g_list_free(list);
- g_hash_table_destroy(ht);
+ g_list_free(list);
+ g_hash_table_destroy(ht);
}
static gboolean
billterm_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return
- gnc_xml2_write_namespace_decl(out, "billterm")
- && gnc_xml2_write_namespace_decl(out, "bt-days")
- && gnc_xml2_write_namespace_decl(out, "bt-prox");
+ g_return_val_if_fail(out, FALSE);
+ return
+ gnc_xml2_write_namespace_decl(out, "billterm")
+ && gnc_xml2_write_namespace_decl(out, "bt-days")
+ && gnc_xml2_write_namespace_decl(out, "bt-prox");
}
void
gnc_billterm_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_billterm_string,
- billterm_sixtp_parser_create,
- NULL, /* add_item */
- billterm_get_count,
- billterm_write,
- billterm_scrub,
- billterm_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_billterm_string,
+ billterm_sixtp_parser_create,
+ NULL, /* add_item */
+ billterm_get_count,
+ billterm_write,
+ billterm_scrub,
+ billterm_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
GncBillTerm *
gnc_billterm_xml_find_or_create(QofBook *book, GUID *guid)
{
- GncBillTerm *term;
+ GncBillTerm *term;
- g_return_val_if_fail(book, NULL);
- g_return_val_if_fail(guid, NULL);
- term = gncBillTermLookup(book, guid);
- DEBUG("looking for billterm %s, found %p", guid_to_string(guid), term);
- if (!term) {
- term = gncBillTermCreate(book);
- gncBillTermBeginEdit(term);
- gncBillTermSetGUID(term, guid);
- gncBillTermCommitEdit(term);
- DEBUG("Created term: %p", term);
- } else
- gncBillTermDecRef(term);
+ g_return_val_if_fail(book, NULL);
+ g_return_val_if_fail(guid, NULL);
+ term = gncBillTermLookup(book, guid);
+ DEBUG("looking for billterm %s, found %p", guid_to_string(guid), term);
+ if (!term)
+ {
+ term = gncBillTermCreate(book);
+ gncBillTermBeginEdit(term);
+ gncBillTermSetGUID(term, guid);
+ gncBillTermCommitEdit(term);
+ DEBUG("Created term: %p", term);
+ }
+ else
+ gncBillTermDecRef(term);
- return term;
+ return term;
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-customer-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-customer-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-customer-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -86,54 +86,54 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST customer_version_string);
xmlAddChild(ret, guid_to_dom_tree(cust_guid_string,
- qof_instance_get_guid(QOF_INSTANCE(cust))));
+ qof_instance_get_guid(QOF_INSTANCE(cust))));
xmlAddChild(ret, text_to_dom_tree(cust_name_string,
gncCustomerGetName (cust)));
-
+
xmlAddChild(ret, text_to_dom_tree(cust_id_string,
gncCustomerGetID (cust)));
xmlAddChild(ret, gnc_address_to_dom_tree(cust_addr_string,
- gncCustomerGetAddr (cust)));
-
+ gncCustomerGetAddr (cust)));
+
xmlAddChild(ret, gnc_address_to_dom_tree(cust_shipaddr_string,
- gncCustomerGetShipAddr (cust)));
-
+ gncCustomerGetShipAddr (cust)));
+
maybe_add_string (ret, cust_notes_string, gncCustomerGetNotes (cust));
term = gncCustomerGetTerms (cust);
if (term)
- xmlAddChild(ret, guid_to_dom_tree(cust_terms_string,
- qof_instance_get_guid (QOF_INSTANCE(term))));
+ xmlAddChild(ret, guid_to_dom_tree(cust_terms_string,
+ qof_instance_get_guid (QOF_INSTANCE(term))));
xmlAddChild(ret, text_to_dom_tree(cust_taxincluded_string,
- gncTaxIncludedTypeToString (
- gncCustomerGetTaxIncluded (cust))));
+ gncTaxIncludedTypeToString (
+ gncCustomerGetTaxIncluded (cust))));
xmlAddChild(ret, int_to_dom_tree(cust_active_string,
- gncCustomerGetActive (cust)));
+ gncCustomerGetActive (cust)));
num = gncCustomerGetDiscount (cust);
xmlAddChild(ret, gnc_numeric_to_dom_tree(cust_discount_string, &num));
-
+
num = gncCustomerGetCredit (cust);
xmlAddChild(ret, gnc_numeric_to_dom_tree(cust_credit_string, &num));
xmlAddChild
- (ret,
- commodity_ref_to_dom_tree(cust_currency_string,
- gncCustomerGetCurrency (cust)));
+ (ret,
+ commodity_ref_to_dom_tree(cust_currency_string,
+ gncCustomerGetCurrency (cust)));
xmlAddChild (ret, int_to_dom_tree (cust_taxtableoverride_string,
- gncCustomerGetTaxTableOverride (cust)));
+ gncCustomerGetTaxTableOverride (cust)));
taxtable = gncCustomerGetTaxTable (cust);
if (taxtable)
- xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
- qof_instance_get_guid(QOF_INSTANCE(taxtable))));
+ xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
+ qof_instance_get_guid(QOF_INSTANCE(taxtable))));
- kvpnode = kvp_frame_to_dom_tree (cust_slots_string,
- qof_instance_get_slots (QOF_INSTANCE(cust)));
+ kvpnode = kvp_frame_to_dom_tree (cust_slots_string,
+ qof_instance_get_slots (QOF_INSTANCE(cust)));
if (kvpnode) xmlAddChild (ret, kvpnode);
return ret;
@@ -143,34 +143,34 @@
struct customer_pdata
{
- GncCustomer *customer;
- QofBook *book;
+ GncCustomer *customer;
+ QofBook *book;
};
static gboolean
set_string(xmlNodePtr node, GncCustomer* cust,
void (*func)(GncCustomer *cust, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(cust, txt);
-
- g_free(txt);
-
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(cust, txt);
+
+ g_free(txt);
+
+ return TRUE;
}
static gboolean
set_boolean(xmlNodePtr node, GncCustomer* cust,
- void (*func)(GncCustomer* cust, gboolean b))
+ void (*func)(GncCustomer* cust, gboolean b))
{
gint64 val;
gboolean ret;
ret = dom_tree_to_integer(node, &val);
if (ret)
- func(cust, (gboolean)val);
+ func(cust, (gboolean)val);
return ret;
}
@@ -193,16 +193,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail(guid, FALSE);
cust = gncCustomerLookup (pdata->book, guid);
- if (cust) {
- gncCustomerDestroy (pdata->customer);
- pdata->customer = cust;
- gncCustomerBeginEdit (cust);
- } else {
- gncCustomerSetGUID(pdata->customer, guid);
+ if (cust)
+ {
+ gncCustomerDestroy (pdata->customer);
+ pdata->customer = cust;
+ gncCustomerBeginEdit (cust);
}
+ else
+ {
+ gncCustomerSetGUID(pdata->customer, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -235,7 +238,7 @@
g_assert(term);
g_free (guid);
gncCustomerSetTerms (pdata->customer, term);
-
+
return TRUE;
}
@@ -253,7 +256,7 @@
struct customer_pdata *pdata = cust_pdata;
return gnc_dom_tree_to_address (node,
- gncCustomerGetShipAddr(pdata->customer));
+ gncCustomerGetShipAddr(pdata->customer));
}
@@ -272,7 +275,7 @@
g_free (str);
if (ret)
- gncCustomerSetTaxIncluded(pdata->customer, type);
+ gncCustomerSetTaxIncluded(pdata->customer, type);
return ret;
}
@@ -338,13 +341,15 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
taxtable = gncTaxTableLookup (pdata->book, guid);
- if (!taxtable) {
- taxtable = gncTaxTableCreate (pdata->book);
- gncTaxTableBeginEdit (taxtable);
- gncTaxTableSetGUID (taxtable, guid);
- gncTaxTableCommitEdit (taxtable);
- } else
- gncTaxTableDecRef (taxtable);
+ if (!taxtable)
+ {
+ taxtable = gncTaxTableCreate (pdata->book);
+ gncTaxTableBeginEdit (taxtable);
+ gncTaxTableSetGUID (taxtable, guid);
+ gncTaxTableCommitEdit (taxtable);
+ }
+ else
+ gncTaxTableDecRef (taxtable);
gncCustomerSetTaxTable (pdata->customer, taxtable);
g_free(guid);
@@ -361,12 +366,13 @@
static gboolean
customer_slots_handler (xmlNodePtr node, gpointer cust_pdata)
{
- struct customer_pdata *pdata = cust_pdata;
- return dom_tree_to_kvp_frame_given (node,
- qof_instance_get_slots (QOF_INSTANCE(pdata->customer)));
+ struct customer_pdata *pdata = cust_pdata;
+ return dom_tree_to_kvp_frame_given (node,
+ qof_instance_get_slots (QOF_INSTANCE(pdata->customer)));
}
-static struct dom_tree_handler customer_handlers_v2[] = {
+static struct dom_tree_handler customer_handlers_v2[] =
+{
{ cust_name_string, customer_name_handler, 1, 0 },
{ cust_guid_string, customer_guid_handler, 1, 0 },
{ cust_id_string, customer_id_handler, 1, 0 },
@@ -400,7 +406,7 @@
&cust_pdata);
if (successful)
- gncCustomerCommitEdit (cust_pdata.customer);
+ gncCustomerCommitEdit (cust_pdata.customer);
else
{
PERR ("failed to parse customer tree");
@@ -413,9 +419,9 @@
static gboolean
gnc_customer_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncCustomer *cust;
@@ -425,14 +431,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -440,7 +446,7 @@
g_return_val_if_fail(tree, FALSE);
cust = dom_tree_to_customer(tree, book);
- if(cust != NULL)
+ if (cust != NULL)
{
gdata->cb(tag, gdata->parsedata, cust);
}
@@ -453,86 +459,87 @@
static sixtp *
customer_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_customer_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_customer_end_handler, NULL, NULL);
}
static gboolean
customer_should_be_saved (GncCustomer *customer)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid customer before we save it -- should have an ID */
- id = gncCustomerGetID (customer);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid customer before we save it -- should have an ID */
+ id = gncCustomerGetID (customer);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * cust_p, gpointer count_p)
{
- int *count = count_p;
- if (customer_should_be_saved ((GncCustomer *)cust_p))
- (*count)++;
+ int *count = count_p;
+ if (customer_should_be_saved ((GncCustomer *)cust_p))
+ (*count)++;
}
static int
customer_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_customer (QofInstance * cust_p, gpointer out_p)
{
- xmlNodePtr node;
- GncCustomer *cust = (GncCustomer *) cust_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncCustomer *cust = (GncCustomer *) cust_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!customer_should_be_saved (cust))
- return;
+ if (ferror(out))
+ return;
+ if (!customer_should_be_saved (cust))
+ return;
- node = customer_dom_tree_create (cust);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = customer_dom_tree_create (cust);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
customer_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
customer_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "cust");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "cust");
}
void
gnc_customer_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_customer_string,
- customer_sixtp_parser_create,
- NULL, /* add_item */
- customer_get_count,
- customer_write,
- NULL, /* scrub */
- customer_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_customer_string,
+ customer_sixtp_parser_create,
+ NULL, /* add_item */
+ customer_get_count,
+ customer_write,
+ NULL, /* scrub */
+ customer_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-employee-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-employee-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-employee-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -69,8 +69,8 @@
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
static xmlNodePtr
@@ -84,23 +84,23 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST employee_version_string);
xmlAddChild(ret, guid_to_dom_tree(employee_guid_string,
- qof_instance_get_guid(QOF_INSTANCE (employee))));
+ qof_instance_get_guid(QOF_INSTANCE (employee))));
xmlAddChild(ret, text_to_dom_tree(employee_username_string,
gncEmployeeGetUsername (employee)));
-
+
xmlAddChild(ret, text_to_dom_tree(employee_id_string,
gncEmployeeGetID (employee)));
xmlAddChild(ret, gnc_address_to_dom_tree(employee_addr_string,
- gncEmployeeGetAddr (employee)));
-
+ gncEmployeeGetAddr (employee)));
+
maybe_add_string (ret, employee_language_string,
- gncEmployeeGetLanguage (employee));
+ gncEmployeeGetLanguage (employee));
maybe_add_string (ret, employee_acl_string, gncEmployeeGetAcl (employee));
xmlAddChild(ret, int_to_dom_tree(employee_active_string,
- gncEmployeeGetActive (employee)));
+ gncEmployeeGetActive (employee)));
num = gncEmployeeGetWorkday (employee);
xmlAddChild(ret, gnc_numeric_to_dom_tree (employee_workday_string, &num));
@@ -109,17 +109,17 @@
xmlAddChild(ret, gnc_numeric_to_dom_tree (employee_rate_string, &num));
xmlAddChild
- (ret,
- commodity_ref_to_dom_tree(employee_currency_string,
- gncEmployeeGetCurrency (employee)));
+ (ret,
+ commodity_ref_to_dom_tree(employee_currency_string,
+ gncEmployeeGetCurrency (employee)));
ccard_acc = gncEmployeeGetCCard (employee);
if (ccard_acc)
- xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string,
- qof_instance_get_guid(QOF_INSTANCE(ccard_acc))));
+ xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string,
+ qof_instance_get_guid(QOF_INSTANCE(ccard_acc))));
kvpnode = kvp_frame_to_dom_tree (employee_slots_string,
- qof_instance_get_slots (QOF_INSTANCE(employee)));
+ qof_instance_get_slots (QOF_INSTANCE(employee)));
if (kvpnode) xmlAddChild (ret, kvpnode);
return ret;
@@ -129,22 +129,22 @@
struct employee_pdata
{
- GncEmployee *employee;
- QofBook *book;
+ GncEmployee *employee;
+ QofBook *book;
};
static gboolean
set_string(xmlNodePtr node, GncEmployee* employee,
void (*func)(GncEmployee *employee, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(employee, txt);
-
- g_free(txt);
-
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(employee, txt);
+
+ g_free(txt);
+
+ return TRUE;
}
static gboolean
@@ -167,16 +167,19 @@
/* See if we've already created this one */
employee = gncEmployeeLookup (pdata->book, guid);
- if (employee) {
- gncEmployeeDestroy (pdata->employee);
- pdata->employee = employee;
- gncEmployeeBeginEdit (employee);
- } else {
- gncEmployeeSetGUID(pdata->employee, guid);
+ if (employee)
+ {
+ gncEmployeeDestroy (pdata->employee);
+ pdata->employee = employee;
+ gncEmployeeBeginEdit (employee);
}
+ else
+ {
+ gncEmployeeSetGUID(pdata->employee, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -221,7 +224,7 @@
ret = dom_tree_to_integer(node, &val);
if (ret)
- gncEmployeeSetActive(pdata->employee, (gboolean)val);
+ gncEmployeeSetActive(pdata->employee, (gboolean)val);
return ret;
}
@@ -292,10 +295,11 @@
{
struct employee_pdata *pdata = employee_pdata;
return dom_tree_to_kvp_frame_given (
- node, qof_instance_get_slots (QOF_INSTANCE(pdata->employee)));
+ node, qof_instance_get_slots (QOF_INSTANCE(pdata->employee)));
}
-static struct dom_tree_handler employee_handlers_v2[] = {
+static struct dom_tree_handler employee_handlers_v2[] =
+{
{ employee_username_string, employee_username_handler, 1, 0 },
{ employee_guid_string, employee_guid_handler, 1, 0 },
{ employee_id_string, employee_id_handler, 1, 0 },
@@ -325,7 +329,7 @@
successful = dom_tree_generic_parse (node, employee_handlers_v2,
&employee_pdata);
if (successful)
- gncEmployeeCommitEdit (employee_pdata.employee);
+ gncEmployeeCommitEdit (employee_pdata.employee);
else
{
PERR ("failed to parse employee tree");
@@ -338,9 +342,9 @@
static gboolean
gnc_employee_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncEmployee *employee;
@@ -350,14 +354,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -365,7 +369,7 @@
g_return_val_if_fail(tree, FALSE);
employee = dom_tree_to_employee(tree, book);
- if(employee != NULL)
+ if (employee != NULL)
{
gdata->cb(tag, gdata->parsedata, employee);
}
@@ -378,86 +382,87 @@
static sixtp *
employee_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_employee_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_employee_end_handler, NULL, NULL);
}
static gboolean
employee_should_be_saved (GncEmployee *employee)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid employee before we save it -- should have an ID */
- id = gncEmployeeGetID (employee);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid employee before we save it -- should have an ID */
+ id = gncEmployeeGetID (employee);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * employee_p, gpointer count_p)
{
- int *count = count_p;
- if (employee_should_be_saved ((GncEmployee *) employee_p))
- (*count)++;
+ int *count = count_p;
+ if (employee_should_be_saved ((GncEmployee *) employee_p))
+ (*count)++;
}
static int
employee_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_employee (QofInstance * employee_p, gpointer out_p)
{
- xmlNodePtr node;
- GncEmployee *employee = (GncEmployee *) employee_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncEmployee *employee = (GncEmployee *) employee_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!employee_should_be_saved (employee))
- return;
+ if (ferror(out))
+ return;
+ if (!employee_should_be_saved (employee))
+ return;
- node = employee_dom_tree_create (employee);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = employee_dom_tree_create (employee);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
employee_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
employee_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "employee");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "employee");
}
void
gnc_employee_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_employee_string,
- employee_sixtp_parser_create,
- NULL, /* add_item */
- employee_get_count,
- employee_write,
- NULL, /* scrub */
- employee_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_employee_string,
+ employee_sixtp_parser_create,
+ NULL, /* add_item */
+ employee_get_count,
+ employee_write,
+ NULL, /* scrub */
+ employee_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-entry-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-entry-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-entry-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -95,15 +95,15 @@
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
static void
maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric num)
{
- if (!gnc_numeric_zero_p (num))
- xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &num));
+ if (!gnc_numeric_zero_p (num))
+ xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &num));
}
static xmlNodePtr
@@ -120,16 +120,16 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST entry_version_string);
xmlAddChild(ret, guid_to_dom_tree(entry_guid_string,
- qof_instance_get_guid(QOF_INSTANCE(entry))));
+ qof_instance_get_guid(QOF_INSTANCE(entry))));
ts = gncEntryGetDate (entry);
xmlAddChild(ret, timespec_to_dom_tree (entry_date_string, &ts));
ts = gncEntryGetDateEntered (entry);
xmlAddChild(ret, timespec_to_dom_tree (entry_dateentered_string, &ts));
-
+
maybe_add_string (ret, entry_description_string,
- gncEntryGetDescription (entry));
+ gncEntryGetDescription (entry));
maybe_add_string (ret, entry_action_string, gncEntryGetAction (entry));
maybe_add_string (ret, entry_notes_string, gncEntryGetNotes (entry));
@@ -139,75 +139,77 @@
acc = gncEntryGetInvAccount (entry);
if (acc)
- xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
- qof_instance_get_guid(QOF_INSTANCE(acc))));
+ xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
+ qof_instance_get_guid(QOF_INSTANCE(acc))));
maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry));
maybe_add_numeric (ret, entry_idiscount_string, gncEntryGetInvDiscount (entry));
-
+
invoice = gncEntryGetInvoice (entry);
- if (invoice) {
- xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
- qof_instance_get_guid(QOF_INSTANCE(invoice))));
+ if (invoice)
+ {
+ xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
+ qof_instance_get_guid(QOF_INSTANCE(invoice))));
- xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
- gncAmountTypeToString (
- gncEntryGetInvDiscountType (entry))));
- xmlAddChild(ret, text_to_dom_tree(entry_idischow_string,
- gncEntryDiscountHowToString (
- gncEntryGetInvDiscountHow (entry))));
+ xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
+ gncAmountTypeToString (
+ gncEntryGetInvDiscountType (entry))));
+ xmlAddChild(ret, text_to_dom_tree(entry_idischow_string,
+ gncEntryDiscountHowToString (
+ gncEntryGetInvDiscountHow (entry))));
- xmlAddChild(ret, int_to_dom_tree(entry_itaxable_string,
- gncEntryGetInvTaxable (entry)));
- xmlAddChild(ret, int_to_dom_tree(entry_itaxincluded_string,
- gncEntryGetInvTaxIncluded (entry)));
+ xmlAddChild(ret, int_to_dom_tree(entry_itaxable_string,
+ gncEntryGetInvTaxable (entry)));
+ xmlAddChild(ret, int_to_dom_tree(entry_itaxincluded_string,
+ gncEntryGetInvTaxIncluded (entry)));
}
taxtable = gncEntryGetInvTaxTable (entry);
if (taxtable)
- xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
- qof_instance_get_guid (QOF_INSTANCE(taxtable))));
+ xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
+ qof_instance_get_guid (QOF_INSTANCE(taxtable))));
/* vendor bills */
acc = gncEntryGetBillAccount (entry);
if (acc)
- xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
- qof_instance_get_guid (QOF_INSTANCE(acc))));
+ xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
+ qof_instance_get_guid (QOF_INSTANCE(acc))));
maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry));
invoice = gncEntryGetBill (entry);
- if (invoice) {
- GncOwner *owner;
- xmlAddChild (ret, guid_to_dom_tree (entry_bill_string,
- qof_instance_get_guid(QOF_INSTANCE(invoice))));
- xmlAddChild(ret, int_to_dom_tree(entry_billable_string,
- gncEntryGetBillable (entry)));
- owner = gncEntryGetBillTo (entry);
- if (owner && owner->owner.undefined != NULL)
- xmlAddChild (ret, gnc_owner_to_dom_tree (entry_billto_string, owner));
+ if (invoice)
+ {
+ GncOwner *owner;
+ xmlAddChild (ret, guid_to_dom_tree (entry_bill_string,
+ qof_instance_get_guid(QOF_INSTANCE(invoice))));
+ xmlAddChild(ret, int_to_dom_tree(entry_billable_string,
+ gncEntryGetBillable (entry)));
+ owner = gncEntryGetBillTo (entry);
+ if (owner && owner->owner.undefined != NULL)
+ xmlAddChild (ret, gnc_owner_to_dom_tree (entry_billto_string, owner));
- xmlAddChild(ret, int_to_dom_tree(entry_btaxable_string,
- gncEntryGetBillTaxable (entry)));
- xmlAddChild(ret, int_to_dom_tree(entry_btaxincluded_string,
- gncEntryGetBillTaxIncluded (entry)));
- maybe_add_string (ret, entry_billpayment_string,
- gncEntryPaymentTypeToString (gncEntryGetBillPayment (entry)));
+ xmlAddChild(ret, int_to_dom_tree(entry_btaxable_string,
+ gncEntryGetBillTaxable (entry)));
+ xmlAddChild(ret, int_to_dom_tree(entry_btaxincluded_string,
+ gncEntryGetBillTaxIncluded (entry)));
+ maybe_add_string (ret, entry_billpayment_string,
+ gncEntryPaymentTypeToString (gncEntryGetBillPayment (entry)));
}
taxtable = gncEntryGetBillTaxTable (entry);
if (taxtable)
- xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
- qof_instance_get_guid (QOF_INSTANCE(taxtable))));
+ xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
+ qof_instance_get_guid (QOF_INSTANCE(taxtable))));
/* Other stuff */
order = gncEntryGetOrder (entry);
if (order)
- xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
- qof_instance_get_guid(QOF_INSTANCE (order))));
+ xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
+ qof_instance_get_guid(QOF_INSTANCE (order))));
return ret;
}
@@ -216,61 +218,61 @@
struct entry_pdata
{
- GncEntry *entry;
- QofBook *book;
- Account *acc;
+ GncEntry *entry;
+ QofBook *book;
+ Account *acc;
};
static inline gboolean
set_string(xmlNodePtr node, GncEntry* entry,
void (*func)(GncEntry *entry, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(entry, txt);
- g_free(txt);
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(entry, txt);
+ g_free(txt);
+ return TRUE;
}
static inline gboolean
set_timespec(xmlNodePtr node, GncEntry* entry,
- void (*func)(GncEntry *entry, Timespec ts))
+ void (*func)(GncEntry *entry, Timespec ts))
{
- Timespec ts = dom_tree_to_timespec (node);
- if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
-
- func(entry, ts);
- return TRUE;
+ Timespec ts = dom_tree_to_timespec (node);
+ if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
+
+ func(entry, ts);
+ return TRUE;
}
static inline gboolean
set_numeric(xmlNodePtr node, GncEntry* entry,
- void (*func)(GncEntry *entry, gnc_numeric num))
+ void (*func)(GncEntry *entry, gnc_numeric num))
{
- gnc_numeric* num = dom_tree_to_gnc_numeric(node);
- g_return_val_if_fail(num, FALSE);
-
- func(entry, *num);
- g_free(num);
- return TRUE;
+ gnc_numeric* num = dom_tree_to_gnc_numeric(node);
+ g_return_val_if_fail(num, FALSE);
+
+ func(entry, *num);
+ g_free(num);
+ return TRUE;
}
static inline gboolean
set_boolean(xmlNodePtr node, GncEntry* entry,
- void (*func)(GncEntry *entry, gboolean val))
+ void (*func)(GncEntry *entry, gboolean val))
{
gint64 val;
if (!dom_tree_to_integer(node, &val))
- return FALSE;
+ return FALSE;
func (entry, (gboolean)val);
return TRUE;
}
static inline gboolean
set_account(xmlNodePtr node, struct entry_pdata *pdata,
- void (*func)(GncEntry *entry, Account *acc))
+ void (*func)(GncEntry *entry, Account *acc))
{
GUID *guid;
Account * acc;
@@ -282,15 +284,15 @@
g_return_val_if_fail (acc, FALSE);
if (func)
- func (pdata->entry, acc);
+ func (pdata->entry, acc);
else
- pdata->acc = acc;
+ pdata->acc = acc;
return TRUE;
}
static inline gboolean
set_taxtable (xmlNodePtr node, struct entry_pdata *pdata,
- void (*func)(GncEntry *entry, GncTaxTable *taxtable))
+ void (*func)(GncEntry *entry, GncTaxTable *taxtable))
{
GUID *guid;
GncTaxTable *taxtable;
@@ -298,13 +300,15 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
taxtable = gncTaxTableLookup (pdata->book, guid);
- if (!taxtable) {
- taxtable = gncTaxTableCreate (pdata->book);
- gncTaxTableBeginEdit (taxtable);
- gncTaxTableSetGUID (taxtable, guid);
- gncTaxTableCommitEdit (taxtable);
- } else
- gncTaxTableDecRef (taxtable);
+ if (!taxtable)
+ {
+ taxtable = gncTaxTableCreate (pdata->book);
+ gncTaxTableBeginEdit (taxtable);
+ gncTaxTableSetGUID (taxtable, guid);
+ gncTaxTableCommitEdit (taxtable);
+ }
+ else
+ gncTaxTableDecRef (taxtable);
func (pdata->entry, taxtable);
g_free(guid);
@@ -321,16 +325,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
entry = gncEntryLookup (pdata->book, guid);
- if (entry) {
- gncEntryDestroy (pdata->entry);
- pdata->entry = entry;
- gncEntryBeginEdit (entry);
- } else {
- gncEntrySetGUID(pdata->entry, guid);
+ if (entry)
+ {
+ gncEntryDestroy (pdata->entry);
+ pdata->entry = entry;
+ gncEntryBeginEdit (entry);
}
+ else
+ {
+ gncEntrySetGUID(pdata->entry, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -422,7 +429,7 @@
g_free (str);
if (ret)
- gncEntrySetInvDiscountType(pdata->entry, type);
+ gncEntrySetInvDiscountType(pdata->entry, type);
return ret;
}
@@ -442,7 +449,7 @@
g_free (str);
if (ret)
- gncEntrySetInvDiscountHow(pdata->entry, how);
+ gncEntrySetInvDiscountHow(pdata->entry, how);
return ret;
}
@@ -516,15 +523,15 @@
static gboolean
entry_billto_handler (xmlNodePtr node, gpointer entry_pdata)
{
- struct entry_pdata *pdata = entry_pdata;
- GncOwner billto;
- gboolean ret;
+ struct entry_pdata *pdata = entry_pdata;
+ GncOwner billto;
+ gboolean ret;
- ret = gnc_dom_tree_to_owner (node, &billto, pdata->book);
- if (ret)
- gncEntrySetBillTo (pdata->entry, &billto);
+ ret = gnc_dom_tree_to_owner (node, &billto, pdata->book);
+ if (ret)
+ gncEntrySetBillTo (pdata->entry, &billto);
- return ret;
+ return ret;
}
/* employee bills */
@@ -543,7 +550,7 @@
g_free (str);
if (ret)
- gncEntrySetBillPayment(pdata->entry, type);
+ gncEntrySetBillPayment(pdata->entry, type);
return ret;
}
@@ -560,11 +567,12 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
order = gncOrderLookup (pdata->book, guid);
- if (!order) {
- order = gncOrderCreate (pdata->book);
- gncOrderBeginEdit (order);
- gncOrderSetGUID (order, guid);
- gncOrderCommitEdit (order);
+ if (!order)
+ {
+ order = gncOrderCreate (pdata->book);
+ gncOrderBeginEdit (order);
+ gncOrderSetGUID (order, guid);
+ gncOrderCommitEdit (order);
}
gncOrderBeginEdit (order);
gncOrderAddEntry (order, pdata->entry);
@@ -584,11 +592,12 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
invoice = gncInvoiceLookup (pdata->book, guid);
- if (!invoice) {
- invoice = gncInvoiceCreate (pdata->book);
- gncInvoiceBeginEdit (invoice);
- gncInvoiceSetGUID (invoice, guid);
- gncInvoiceCommitEdit (invoice);
+ if (!invoice)
+ {
+ invoice = gncInvoiceCreate (pdata->book);
+ gncInvoiceBeginEdit (invoice);
+ gncInvoiceSetGUID (invoice, guid);
+ gncInvoiceCommitEdit (invoice);
}
gncInvoiceBeginEdit (invoice);
gncInvoiceAddEntry (invoice, pdata->entry);
@@ -608,11 +617,12 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
invoice = gncInvoiceLookup (pdata->book, guid);
- if (!invoice) {
- invoice = gncInvoiceCreate (pdata->book);
- gncInvoiceBeginEdit (invoice);
- gncInvoiceSetGUID (invoice, guid);
- gncInvoiceCommitEdit (invoice);
+ if (!invoice)
+ {
+ invoice = gncInvoiceCreate (pdata->book);
+ gncInvoiceBeginEdit (invoice);
+ gncInvoiceSetGUID (invoice, guid);
+ gncInvoiceCommitEdit (invoice);
}
gncInvoiceBeginEdit (invoice);
gncBillAddEntry (invoice, pdata->entry);
@@ -644,17 +654,18 @@
/* just set both.. Don't worry about extra data if it's wrong */
res = set_numeric(node, pdata->entry, gncEntrySetInvPrice);
if (res)
- gncEntrySetBillPrice (pdata->entry, gncEntryGetInvPrice (pdata->entry));
+ gncEntrySetBillPrice (pdata->entry, gncEntryGetInvPrice (pdata->entry));
return res;
}
static gboolean
entry_slots_handler (xmlNodePtr node, gpointer entry_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler entry_handlers_v2[] = {
+static struct dom_tree_handler entry_handlers_v2[] =
+{
{ entry_guid_string, entry_guid_handler, 1, 0 },
{ entry_date_string, entry_date_handler, 1, 0 },
{ entry_dateentered_string, entry_dateentered_handler, 1, 0 },
@@ -716,15 +727,16 @@
successful = dom_tree_generic_parse (node, entry_handlers_v2,
&entry_pdata);
- if (entry_pdata.acc != NULL) {
- if (gncEntryGetBill (entry_pdata.entry))
- gncEntrySetBillAccount (entry_pdata.entry, entry_pdata.acc);
- else
- gncEntrySetInvAccount (entry_pdata.entry, entry_pdata.acc);
+ if (entry_pdata.acc != NULL)
+ {
+ if (gncEntryGetBill (entry_pdata.entry))
+ gncEntrySetBillAccount (entry_pdata.entry, entry_pdata.acc);
+ else
+ gncEntrySetInvAccount (entry_pdata.entry, entry_pdata.acc);
}
if (successful)
- gncEntryCommitEdit (entry_pdata.entry);
+ gncEntryCommitEdit (entry_pdata.entry);
else
{
PERR ("failed to parse entry tree");
@@ -737,9 +749,9 @@
static gboolean
gnc_entry_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncEntry *entry;
@@ -749,14 +761,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -764,7 +776,7 @@
g_return_val_if_fail(tree, FALSE);
entry = dom_tree_to_entry(tree, book);
- if(entry != NULL)
+ if (entry != NULL)
{
gdata->cb(tag, gdata->parsedata, entry);
}
@@ -777,75 +789,76 @@
static sixtp *
entry_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_entry_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_entry_end_handler, NULL, NULL);
}
static void
do_count (QofInstance * entry_p, gpointer count_p)
{
- int *count = count_p;
- (*count)++;
+ int *count = count_p;
+ (*count)++;
}
static int
entry_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_entry (QofInstance * entry_p, gpointer out_p)
{
- xmlNodePtr node;
- GncEntry *entry = (GncEntry *) entry_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncEntry *entry = (GncEntry *) entry_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
+ if (ferror(out))
+ return;
- /* Don't save non-attached entries! */
- if (!(gncEntryGetOrder (entry) || gncEntryGetInvoice (entry) ||
- gncEntryGetBill (entry)))
- return;
+ /* Don't save non-attached entries! */
+ if (!(gncEntryGetOrder (entry) || gncEntryGetInvoice (entry) ||
+ gncEntryGetBill (entry)))
+ return;
- node = entry_dom_tree_create (entry);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = entry_dom_tree_create (entry);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
entry_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
entry_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "entry");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "entry");
}
void
gnc_entry_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_entry_string,
- entry_sixtp_parser_create,
- NULL, /* add_item */
- entry_get_count,
- entry_write,
- NULL, /* scrub */
- entry_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_entry_string,
+ entry_sixtp_parser_create,
+ NULL, /* add_item */
+ entry_get_count,
+ entry_write,
+ NULL, /* scrub */
+ entry_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-invoice-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-invoice-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-invoice-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -75,15 +75,15 @@
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
static void
maybe_add_timespec (xmlNodePtr ptr, const char *tag, Timespec ts)
{
- if (ts.tv_sec || ts.tv_nsec)
- xmlAddChild (ptr, timespec_to_dom_tree (tag, &ts));
+ if (ts.tv_sec || ts.tv_nsec)
+ xmlAddChild (ptr, timespec_to_dom_tree (tag, &ts));
}
static xmlNodePtr
@@ -102,59 +102,59 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST invoice_version_string);
xmlAddChild(ret, guid_to_dom_tree(invoice_guid_string,
- qof_instance_get_guid(QOF_INSTANCE(invoice))));
+ qof_instance_get_guid(QOF_INSTANCE(invoice))));
xmlAddChild(ret, text_to_dom_tree(invoice_id_string,
gncInvoiceGetID (invoice)));
xmlAddChild(ret, gnc_owner_to_dom_tree (invoice_owner_string,
- gncInvoiceGetOwner (invoice)));
+ gncInvoiceGetOwner (invoice)));
ts = gncInvoiceGetDateOpened (invoice);
xmlAddChild(ret, timespec_to_dom_tree (invoice_opened_string, &ts));
maybe_add_timespec (ret, invoice_posted_string,
- gncInvoiceGetDatePosted (invoice));
-
+ gncInvoiceGetDatePosted (invoice));
+
term = gncInvoiceGetTerms (invoice);
if (term)
- xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string,
- qof_instance_get_guid (QOF_INSTANCE(term))));
-
+ xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string,
+ qof_instance_get_guid (QOF_INSTANCE(term))));
+
maybe_add_string (ret, invoice_billing_id_string,
- gncInvoiceGetBillingID (invoice));
+ gncInvoiceGetBillingID (invoice));
maybe_add_string (ret, invoice_notes_string, gncInvoiceGetNotes (invoice));
xmlAddChild(ret, int_to_dom_tree(invoice_active_string,
- gncInvoiceGetActive (invoice)));
+ gncInvoiceGetActive (invoice)));
txn = gncInvoiceGetPostedTxn (invoice);
if (txn)
- xmlAddChild (ret, guid_to_dom_tree (invoice_posttxn_string,
- xaccTransGetGUID (txn)));
+ xmlAddChild (ret, guid_to_dom_tree (invoice_posttxn_string,
+ xaccTransGetGUID (txn)));
lot = gncInvoiceGetPostedLot (invoice);
if (lot)
- xmlAddChild (ret, guid_to_dom_tree (invoice_postlot_string,
- gnc_lot_get_guid (lot)));
+ xmlAddChild (ret, guid_to_dom_tree (invoice_postlot_string,
+ gnc_lot_get_guid (lot)));
acc = gncInvoiceGetPostedAcc (invoice);
if (acc)
- xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string,
- qof_instance_get_guid(QOF_INSTANCE(acc))));
+ xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string,
+ qof_instance_get_guid(QOF_INSTANCE(acc))));
xmlAddChild
- (ret,
- commodity_ref_to_dom_tree(invoice_currency_string,
- gncInvoiceGetCurrency (invoice)));
+ (ret,
+ commodity_ref_to_dom_tree(invoice_currency_string,
+ gncInvoiceGetCurrency (invoice)));
billto = gncInvoiceGetBillTo (invoice);
if (billto && billto->owner.undefined != NULL)
- xmlAddChild (ret, gnc_owner_to_dom_tree (invoice_billto_string, billto));
+ xmlAddChild (ret, gnc_owner_to_dom_tree (invoice_billto_string, billto));
amt = gncInvoiceGetToChargeAmount (invoice);
if (! gnc_numeric_zero_p (amt))
- xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt));
+ xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt));
return ret;
}
@@ -163,32 +163,32 @@
struct invoice_pdata
{
- GncInvoice *invoice;
- QofBook *book;
+ GncInvoice *invoice;
+ QofBook *book;
};
static inline gboolean
set_string(xmlNodePtr node, GncInvoice* invoice,
void (*func)(GncInvoice *invoice, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(invoice, txt);
-
- g_free(txt);
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(invoice, txt);
+
+ g_free(txt);
+ return TRUE;
}
static inline gboolean
set_timespec(xmlNodePtr node, GncInvoice* invoice,
- void (*func)(GncInvoice *invoice, Timespec ts))
+ void (*func)(GncInvoice *invoice, Timespec ts))
{
- Timespec ts = dom_tree_to_timespec(node);
- if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
-
- func(invoice, ts);
- return TRUE;
+ Timespec ts = dom_tree_to_timespec(node);
+ if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
+
+ func(invoice, ts);
+ return TRUE;
}
static gboolean
@@ -201,16 +201,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
invoice = gncInvoiceLookup (pdata->book, guid);
- if (invoice) {
- gncInvoiceDestroy (pdata->invoice);
- pdata->invoice = invoice;
- gncInvoiceBeginEdit (invoice);
- } else {
- gncInvoiceSetGUID(pdata->invoice, guid);
+ if (invoice)
+ {
+ gncInvoiceDestroy (pdata->invoice);
+ pdata->invoice = invoice;
+ gncInvoiceBeginEdit (invoice);
}
+ else
+ {
+ gncInvoiceSetGUID(pdata->invoice, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -225,15 +228,15 @@
static gboolean
invoice_owner_handler (xmlNodePtr node, gpointer invoice_pdata)
{
- struct invoice_pdata *pdata = invoice_pdata;
- GncOwner owner;
- gboolean ret;
+ struct invoice_pdata *pdata = invoice_pdata;
+ GncOwner owner;
+ gboolean ret;
- ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
- if (ret)
- gncInvoiceSetOwner (pdata->invoice, &owner);
+ ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
+ if (ret)
+ gncInvoiceSetOwner (pdata->invoice, &owner);
- return ret;
+ return ret;
}
static gboolean
@@ -277,7 +280,7 @@
ret = dom_tree_to_integer(node, &val);
if (ret)
- gncInvoiceSetActive(pdata->invoice, (gboolean)val);
+ gncInvoiceSetActive(pdata->invoice, (gboolean)val);
return ret;
}
@@ -295,7 +298,7 @@
g_assert(term);
g_free (guid);
gncInvoiceSetTerms (pdata->invoice, term);
-
+
return TRUE;
}
@@ -367,36 +370,37 @@
static gboolean
invoice_billto_handler (xmlNodePtr node, gpointer invoice_pdata)
{
- struct invoice_pdata *pdata = invoice_pdata;
- GncOwner owner;
- gboolean ret;
+ struct invoice_pdata *pdata = invoice_pdata;
+ GncOwner owner;
+ gboolean ret;
- ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
- if (ret)
- gncInvoiceSetBillTo (pdata->invoice, &owner);
+ ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
+ if (ret)
+ gncInvoiceSetBillTo (pdata->invoice, &owner);
- return ret;
+ return ret;
}
static gboolean
invoice_tochargeamt_handler (xmlNodePtr node, gpointer invoice_pdata)
{
- struct invoice_pdata *pdata = invoice_pdata;
- gnc_numeric* num = dom_tree_to_gnc_numeric(node);
- g_return_val_if_fail(num, FALSE);
-
- gncInvoiceSetToChargeAmount (pdata->invoice, *num);
- g_free(num);
- return TRUE;
+ struct invoice_pdata *pdata = invoice_pdata;
+ gnc_numeric* num = dom_tree_to_gnc_numeric(node);
+ g_return_val_if_fail(num, FALSE);
+
+ gncInvoiceSetToChargeAmount (pdata->invoice, *num);
+ g_free(num);
+ return TRUE;
}
static gboolean
invoice_slots_handler (xmlNodePtr node, gpointer invoice_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler invoice_handlers_v2[] = {
+static struct dom_tree_handler invoice_handlers_v2[] =
+{
{ invoice_guid_string, invoice_guid_handler, 1, 0 },
{ invoice_id_string, invoice_id_handler, 1, 0 },
{ invoice_owner_string, invoice_owner_handler, 1, 0 },
@@ -431,7 +435,7 @@
&invoice_pdata);
if (successful)
- gncInvoiceCommitEdit (invoice_pdata.invoice);
+ gncInvoiceCommitEdit (invoice_pdata.invoice);
else
{
PERR ("failed to parse invoice tree");
@@ -444,9 +448,9 @@
static gboolean
gnc_invoice_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncInvoice *invoice;
@@ -456,14 +460,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -471,7 +475,7 @@
g_return_val_if_fail(tree, FALSE);
invoice = dom_tree_to_invoice(tree, book);
- if(invoice != NULL)
+ if (invoice != NULL)
{
gdata->cb(tag, gdata->parsedata, invoice);
}
@@ -484,86 +488,87 @@
static sixtp *
invoice_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_invoice_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_invoice_end_handler, NULL, NULL);
}
static gboolean
invoice_should_be_saved (GncInvoice *invoice)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid invoice before we save it -- should have an ID */
- id = gncInvoiceGetID (invoice);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid invoice before we save it -- should have an ID */
+ id = gncInvoiceGetID (invoice);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * invoice_p, gpointer count_p)
{
- int *count = count_p;
- if (invoice_should_be_saved ((GncInvoice *)invoice_p))
- (*count)++;
+ int *count = count_p;
+ if (invoice_should_be_saved ((GncInvoice *)invoice_p))
+ (*count)++;
}
static int
invoice_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_invoice (QofInstance * invoice_p, gpointer out_p)
{
- xmlNodePtr node;
- GncInvoice *invoice = (GncInvoice *) invoice_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncInvoice *invoice = (GncInvoice *) invoice_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!invoice_should_be_saved (invoice))
- return;
+ if (ferror(out))
+ return;
+ if (!invoice_should_be_saved (invoice))
+ return;
- node = invoice_dom_tree_create (invoice);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = invoice_dom_tree_create (invoice);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
invoice_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
invoice_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "invoice");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "invoice");
}
void
gnc_invoice_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_invoice_string,
- invoice_sixtp_parser_create,
- NULL, /* add_item */
- invoice_get_count,
- invoice_write,
- NULL, /* scrub */
- invoice_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_invoice_string,
+ invoice_sixtp_parser_create,
+ NULL, /* add_item */
+ invoice_get_count,
+ invoice_write,
+ NULL, /* scrub */
+ invoice_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-job-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-job-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-job-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -71,21 +71,21 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST job_version_string);
xmlAddChild(ret, guid_to_dom_tree(job_guid_string,
- qof_instance_get_guid (QOF_INSTANCE (job))));
+ qof_instance_get_guid (QOF_INSTANCE (job))));
xmlAddChild(ret, text_to_dom_tree(job_id_string,
gncJobGetID (job)));
xmlAddChild(ret, text_to_dom_tree(job_name_string,
gncJobGetName (job)));
-
+
maybe_add_string (ret, job_reference_string, gncJobGetReference (job));
xmlAddChild(ret, gnc_owner_to_dom_tree (job_owner_string,
- gncJobGetOwner (job)));
+ gncJobGetOwner (job)));
xmlAddChild(ret, int_to_dom_tree(job_active_string,
- gncJobGetActive (job)));
+ gncJobGetActive (job)));
return ret;
}
@@ -94,22 +94,22 @@
struct job_pdata
{
- GncJob *job;
- QofBook *book;
+ GncJob *job;
+ QofBook *book;
};
static gboolean
set_string(xmlNodePtr node, GncJob* job,
void (*func)(GncJob *job, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(job, txt);
-
- g_free(txt);
-
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(job, txt);
+
+ g_free(txt);
+
+ return TRUE;
}
static gboolean
@@ -130,16 +130,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail(guid, FALSE);
job = gncJobLookup (pdata->book, guid);
- if (job) {
- gncJobDestroy (pdata->job);
- pdata->job = job;
- gncJobBeginEdit (job);
- } else {
- gncJobSetGUID(pdata->job, guid);
+ if (job)
+ {
+ gncJobDestroy (pdata->job);
+ pdata->job = job;
+ gncJobBeginEdit (job);
}
+ else
+ {
+ gncJobSetGUID(pdata->job, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -162,15 +165,15 @@
static gboolean
job_owner_handler (xmlNodePtr node, gpointer job_pdata)
{
- struct job_pdata *pdata = job_pdata;
- GncOwner owner;
- gboolean ret;
+ struct job_pdata *pdata = job_pdata;
+ GncOwner owner;
+ gboolean ret;
- ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
- if (ret)
- gncJobSetOwner (pdata->job, &owner);
+ ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
+ if (ret)
+ gncJobSetOwner (pdata->job, &owner);
- return ret;
+ return ret;
}
static gboolean
@@ -182,7 +185,7 @@
ret = dom_tree_to_integer(node, &val);
if (ret)
- gncJobSetActive(pdata->job, (gboolean)val);
+ gncJobSetActive(pdata->job, (gboolean)val);
return ret;
}
@@ -190,10 +193,11 @@
static gboolean
job_slots_handler (xmlNodePtr node, gpointer job_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler job_handlers_v2[] = {
+static struct dom_tree_handler job_handlers_v2[] =
+{
{ job_guid_string, job_guid_handler, 1, 0 },
{ job_id_string, job_id_handler, 1, 0 },
{ job_name_string, job_name_handler, 1, 0 },
@@ -218,7 +222,7 @@
&job_pdata);
if (successful)
- gncJobCommitEdit (job_pdata.job);
+ gncJobCommitEdit (job_pdata.job);
else
{
PERR ("failed to parse job tree");
@@ -231,9 +235,9 @@
static gboolean
gnc_job_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncJob *job;
@@ -243,14 +247,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -258,7 +262,7 @@
g_return_val_if_fail(tree, FALSE);
job = dom_tree_to_job(tree, book);
- if(job != NULL)
+ if (job != NULL)
{
gdata->cb(tag, gdata->parsedata, job);
}
@@ -271,86 +275,87 @@
static sixtp *
job_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_job_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_job_end_handler, NULL, NULL);
}
static gboolean
job_should_be_saved (GncJob *job)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid job before we save it -- should have an ID */
- id = gncJobGetID (job);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid job before we save it -- should have an ID */
+ id = gncJobGetID (job);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * job_p, gpointer count_p)
{
- int *count = count_p;
- if (job_should_be_saved ((GncJob *)job_p))
- (*count)++;
+ int *count = count_p;
+ if (job_should_be_saved ((GncJob *)job_p))
+ (*count)++;
}
static int
job_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_job (QofInstance * job_p, gpointer out_p)
{
- xmlNodePtr node;
- GncJob *job = (GncJob *) job_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncJob *job = (GncJob *) job_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!job_should_be_saved (job))
- return;
+ if (ferror(out))
+ return;
+ if (!job_should_be_saved (job))
+ return;
- node = job_dom_tree_create (job);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = job_dom_tree_create (job);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
job_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
job_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "job");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "job");
}
void
gnc_job_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_job_string,
- job_sixtp_parser_create,
- NULL, /* add_item */
- job_get_count,
- job_write,
- NULL, /* scrub */
- job_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_job_string,
+ job_sixtp_parser_create,
+ NULL, /* add_item */
+ job_get_count,
+ job_write,
+ NULL, /* scrub */
+ job_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-order-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-order-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-order-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -67,8 +67,8 @@
static void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
static xmlNodePtr
@@ -81,26 +81,26 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST order_version_string);
xmlAddChild(ret, guid_to_dom_tree(order_guid_string,
- qof_instance_get_guid(QOF_INSTANCE (order))));
+ qof_instance_get_guid(QOF_INSTANCE (order))));
xmlAddChild(ret, text_to_dom_tree(order_id_string,
gncOrderGetID (order)));
xmlAddChild(ret, gnc_owner_to_dom_tree (order_owner_string,
- gncOrderGetOwner (order)));
+ gncOrderGetOwner (order)));
ts = gncOrderGetDateOpened (order);
xmlAddChild(ret, timespec_to_dom_tree (order_opened_string, &ts));
ts = gncOrderGetDateClosed (order);
if (ts.tv_sec || ts.tv_nsec)
- xmlAddChild(ret, timespec_to_dom_tree (order_closed_string, &ts));
-
+ xmlAddChild(ret, timespec_to_dom_tree (order_closed_string, &ts));
+
maybe_add_string (ret, order_notes_string, gncOrderGetNotes (order));
maybe_add_string (ret, order_reference_string, gncOrderGetReference (order));
xmlAddChild(ret, int_to_dom_tree(order_active_string,
- gncOrderGetActive (order)));
+ gncOrderGetActive (order)));
return ret;
}
@@ -109,32 +109,32 @@
struct order_pdata
{
- GncOrder *order;
- QofBook *book;
+ GncOrder *order;
+ QofBook *book;
};
static inline gboolean
set_string(xmlNodePtr node, GncOrder* order,
void (*func)(GncOrder *order, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(order, txt);
-
- g_free(txt);
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(order, txt);
+
+ g_free(txt);
+ return TRUE;
}
static inline gboolean
set_timespec(xmlNodePtr node, GncOrder* order,
- void (*func)(GncOrder *order, Timespec ts))
+ void (*func)(GncOrder *order, Timespec ts))
{
- Timespec ts = dom_tree_to_timespec(node);
- if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
-
- func(order, ts);
- return TRUE;
+ Timespec ts = dom_tree_to_timespec(node);
+ if (!dom_tree_valid_timespec(&ts, node->name)) return FALSE;
+
+ func(order, ts);
+ return TRUE;
}
static gboolean
@@ -147,16 +147,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
order = gncOrderLookup (pdata->book, guid);
- if (order) {
- gncOrderDestroy (pdata->order);
- pdata->order = order;
- gncOrderBeginEdit (order);
- } else {
- gncOrderSetGUID(pdata->order, guid);
+ if (order)
+ {
+ gncOrderDestroy (pdata->order);
+ pdata->order = order;
+ gncOrderBeginEdit (order);
}
+ else
+ {
+ gncOrderSetGUID(pdata->order, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -171,15 +174,15 @@
static gboolean
order_owner_handler (xmlNodePtr node, gpointer order_pdata)
{
- struct order_pdata *pdata = order_pdata;
- GncOwner owner;
- gboolean ret;
+ struct order_pdata *pdata = order_pdata;
+ GncOwner owner;
+ gboolean ret;
- ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
- if (ret)
- gncOrderSetOwner (pdata->order, &owner);
+ ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
+ if (ret)
+ gncOrderSetOwner (pdata->order, &owner);
- return ret;
+ return ret;
}
static gboolean
@@ -223,7 +226,7 @@
ret = dom_tree_to_integer(node, &val);
if (ret)
- gncOrderSetActive(pdata->order, (gboolean)val);
+ gncOrderSetActive(pdata->order, (gboolean)val);
return ret;
}
@@ -231,10 +234,11 @@
static gboolean
order_slots_handler (xmlNodePtr node, gpointer order_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler order_handlers_v2[] = {
+static struct dom_tree_handler order_handlers_v2[] =
+{
{ order_guid_string, order_guid_handler, 1, 0 },
{ order_id_string, order_id_handler, 1, 0 },
{ order_owner_string, order_owner_handler, 1, 0 },
@@ -261,7 +265,7 @@
&order_pdata);
if (successful)
- gncOrderCommitEdit (order_pdata.order);
+ gncOrderCommitEdit (order_pdata.order);
else
{
PERR ("failed to parse order tree");
@@ -274,9 +278,9 @@
static gboolean
gnc_order_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncOrder *order;
@@ -286,14 +290,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -301,7 +305,7 @@
g_return_val_if_fail(tree, FALSE);
order = dom_tree_to_order(tree, book);
- if(order != NULL)
+ if (order != NULL)
{
gdata->cb(tag, gdata->parsedata, order);
}
@@ -314,86 +318,87 @@
static sixtp *
order_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_order_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_order_end_handler, NULL, NULL);
}
static gboolean
order_should_be_saved (GncOrder *order)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid order before we save it -- should have an ID */
- id = gncOrderGetID (order);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid order before we save it -- should have an ID */
+ id = gncOrderGetID (order);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * order_p, gpointer count_p)
{
- int *count = count_p;
- if (order_should_be_saved ((GncOrder *) order_p))
- (*count)++;
+ int *count = count_p;
+ if (order_should_be_saved ((GncOrder *) order_p))
+ (*count)++;
}
static int
order_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_order (QofInstance * order_p, gpointer out_p)
{
- xmlNodePtr node;
- GncOrder *order = (GncOrder *) order_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncOrder *order = (GncOrder *) order_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!order_should_be_saved (order))
- return;
+ if (ferror(out))
+ return;
+ if (!order_should_be_saved (order))
+ return;
- node = order_dom_tree_create (order);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = order_dom_tree_create (order);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
order_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_order, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_order, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
order_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "order");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "order");
}
void
gnc_order_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_order_string,
- order_sixtp_parser_create,
- NULL, /* add_item */
- order_get_count,
- order_write,
- NULL, /* scrub */
- order_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_order_string,
+ order_sixtp_parser_create,
+ NULL, /* add_item */
+ order_get_count,
+ order_write,
+ NULL, /* scrub */
+ order_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -61,22 +61,23 @@
xmlNodePtr ret;
const char *type_str;
- switch (gncOwnerGetType (owner)) {
+ switch (gncOwnerGetType (owner))
+ {
case GNC_OWNER_CUSTOMER:
- type_str = GNC_ID_CUSTOMER;
- break;
+ type_str = GNC_ID_CUSTOMER;
+ break;
case GNC_OWNER_JOB:
- type_str = GNC_ID_JOB;
- break;
+ type_str = GNC_ID_JOB;
+ break;
case GNC_OWNER_VENDOR:
- type_str = GNC_ID_VENDOR;
- break;
+ type_str = GNC_ID_VENDOR;
+ break;
case GNC_OWNER_EMPLOYEE:
- type_str = GNC_ID_EMPLOYEE;
- break;
+ type_str = GNC_ID_EMPLOYEE;
+ break;
default:
- PWARN ("Invalid owner type: %d", gncOwnerGetType (owner));
- return NULL;
+ PWARN ("Invalid owner type: %d", gncOwnerGetType (owner));
+ return NULL;
}
ret = xmlNewNode(NULL, BAD_CAST tag);
@@ -84,7 +85,7 @@
xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str));
xmlAddChild (ret, guid_to_dom_tree (owner_id_string,
- gncOwnerGetGUID (owner)));
+ gncOwnerGetGUID (owner)));
return ret;
}
@@ -93,96 +94,103 @@
struct owner_pdata
{
- GncOwner *owner;
- QofBook *book;
+ GncOwner *owner;
+ QofBook *book;
};
static gboolean
owner_type_handler (xmlNodePtr node, gpointer owner_pdata)
{
- struct owner_pdata *pdata = owner_pdata;
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
+ struct owner_pdata *pdata = owner_pdata;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
- if (!safe_strcmp (txt, GNC_ID_CUSTOMER))
- gncOwnerInitCustomer (pdata->owner, NULL);
- else if (!safe_strcmp (txt, GNC_ID_JOB))
- gncOwnerInitJob (pdata->owner, NULL);
- else if (!safe_strcmp (txt, GNC_ID_VENDOR))
- gncOwnerInitVendor (pdata->owner, NULL);
- else if (!safe_strcmp (txt, GNC_ID_EMPLOYEE))
- gncOwnerInitEmployee (pdata->owner, NULL);
- else {
- PWARN ("Unknown owner type: %s", txt);
+ if (!safe_strcmp (txt, GNC_ID_CUSTOMER))
+ gncOwnerInitCustomer (pdata->owner, NULL);
+ else if (!safe_strcmp (txt, GNC_ID_JOB))
+ gncOwnerInitJob (pdata->owner, NULL);
+ else if (!safe_strcmp (txt, GNC_ID_VENDOR))
+ gncOwnerInitVendor (pdata->owner, NULL);
+ else if (!safe_strcmp (txt, GNC_ID_EMPLOYEE))
+ gncOwnerInitEmployee (pdata->owner, NULL);
+ else
+ {
+ PWARN ("Unknown owner type: %s", txt);
+ g_free(txt);
+ return FALSE;
+ }
+
g_free(txt);
- return FALSE;
- }
-
- g_free(txt);
- return TRUE;
+ return TRUE;
}
static gboolean
owner_id_handler (xmlNodePtr node, gpointer owner_pdata)
{
- struct owner_pdata *pdata = owner_pdata;
- GUID *guid;
+ struct owner_pdata *pdata = owner_pdata;
+ GUID *guid;
- guid = dom_tree_to_guid(node);
- g_return_val_if_fail (guid, FALSE);
+ guid = dom_tree_to_guid(node);
+ g_return_val_if_fail (guid, FALSE);
- switch (gncOwnerGetType (pdata->owner)) {
- case GNC_OWNER_CUSTOMER:
- {
- GncCustomer *cust = gncCustomerLookup (pdata->book, guid);
- if (!cust) {
- cust = gncCustomerCreate (pdata->book);
- gncCustomerSetGUID (cust, guid);
+ switch (gncOwnerGetType (pdata->owner))
+ {
+ case GNC_OWNER_CUSTOMER:
+ {
+ GncCustomer *cust = gncCustomerLookup (pdata->book, guid);
+ if (!cust)
+ {
+ cust = gncCustomerCreate (pdata->book);
+ gncCustomerSetGUID (cust, guid);
+ }
+ gncOwnerInitCustomer (pdata->owner, cust);
+ break;
}
- gncOwnerInitCustomer (pdata->owner, cust);
- break;
- }
- case GNC_OWNER_JOB:
- {
- GncJob *job = gncJobLookup (pdata->book, guid);
- if (!job) {
- job = gncJobCreate (pdata->book);
- gncJobSetGUID (job, guid);
+ case GNC_OWNER_JOB:
+ {
+ GncJob *job = gncJobLookup (pdata->book, guid);
+ if (!job)
+ {
+ job = gncJobCreate (pdata->book);
+ gncJobSetGUID (job, guid);
+ }
+ gncOwnerInitJob (pdata->owner, job);
+ break;
}
- gncOwnerInitJob (pdata->owner, job);
- break;
- }
- case GNC_OWNER_VENDOR:
- {
- GncVendor *vendor = gncVendorLookup (pdata->book, guid);
- if (!vendor) {
- vendor = gncVendorCreate (pdata->book);
- gncVendorSetGUID (vendor, guid);
+ case GNC_OWNER_VENDOR:
+ {
+ GncVendor *vendor = gncVendorLookup (pdata->book, guid);
+ if (!vendor)
+ {
+ vendor = gncVendorCreate (pdata->book);
+ gncVendorSetGUID (vendor, guid);
+ }
+ gncOwnerInitVendor (pdata->owner, vendor);
+ break;
}
- gncOwnerInitVendor (pdata->owner, vendor);
- break;
- }
- case GNC_OWNER_EMPLOYEE:
- {
- GncEmployee *employee = gncEmployeeLookup (pdata->book, guid);
- if (!employee) {
- employee = gncEmployeeCreate (pdata->book);
- gncEmployeeSetGUID (employee, guid);
+ case GNC_OWNER_EMPLOYEE:
+ {
+ GncEmployee *employee = gncEmployeeLookup (pdata->book, guid);
+ if (!employee)
+ {
+ employee = gncEmployeeCreate (pdata->book);
+ gncEmployeeSetGUID (employee, guid);
+ }
+ gncOwnerInitEmployee (pdata->owner, employee);
+ break;
}
- gncOwnerInitEmployee (pdata->owner, employee);
- break;
- }
- default:
- PWARN ("Invalid owner type: %d\n", gncOwnerGetType (pdata->owner));
+ default:
+ PWARN ("Invalid owner type: %d\n", gncOwnerGetType (pdata->owner));
+ g_free (guid);
+ return FALSE;
+ }
+
g_free (guid);
- return FALSE;
- }
-
- g_free (guid);
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler owner_handlers_v2[] = {
+static struct dom_tree_handler owner_handlers_v2[] =
+{
{ owner_type_string, owner_type_handler, 1, 0 },
{ owner_id_string, owner_id_handler, 1, 0 },
{ NULL, 0, 0, 0 }
@@ -211,25 +219,26 @@
static gboolean
owner_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "owner");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "owner");
}
void
gnc_owner_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- "gnc:Owner",
- NULL, /* parser_create */
- NULL, /* add_item */
- NULL, /* get_count */
- NULL, /* write */
- NULL, /* scrub */
- owner_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ "gnc:Owner",
+ NULL, /* parser_create */
+ NULL, /* add_item */
+ NULL, /* get_count */
+ NULL, /* write */
+ NULL, /* scrub */
+ owner_ns,
+ };
- qof_object_register_backend ("gnc:Owner",
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend ("gnc:Owner",
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.h
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-owner-xml-v2.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -27,7 +27,7 @@
#include "qof.h"
gboolean gnc_dom_tree_to_owner (xmlNodePtr node, GncOwner *owner,
- QofBook *book);
+ QofBook *book);
xmlNodePtr gnc_owner_to_dom_tree (const char *tag, GncOwner *addr);
void gnc_owner_xml_initialize (void);
Modified: gnucash/trunk/src/business/business-core/xml/gnc-tax-table-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-tax-table-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-tax-table-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -70,33 +70,33 @@
static void
maybe_add_guid (xmlNodePtr ptr, const char *tag, GncTaxTable *table)
{
- if (table)
- xmlAddChild (ptr, guid_to_dom_tree (tag,
- qof_instance_get_guid(QOF_INSTANCE(table))));
+ if (table)
+ xmlAddChild (ptr, guid_to_dom_tree (tag,
+ qof_instance_get_guid(QOF_INSTANCE(table))));
}
static xmlNodePtr
ttentry_dom_tree_create (GncTaxTableEntry *entry)
{
- xmlNodePtr ret;
- Account *account;
- gnc_numeric amount;
+ xmlNodePtr ret;
+ Account *account;
+ gnc_numeric amount;
- ret = xmlNewNode(NULL, BAD_CAST gnc_taxtableentry_string);
+ ret = xmlNewNode(NULL, BAD_CAST gnc_taxtableentry_string);
- account = gncTaxTableEntryGetAccount (entry);
- if (account)
- xmlAddChild(ret, guid_to_dom_tree (ttentry_account_string,
- qof_instance_get_guid (QOF_INSTANCE(account))));
+ account = gncTaxTableEntryGetAccount (entry);
+ if (account)
+ xmlAddChild(ret, guid_to_dom_tree (ttentry_account_string,
+ qof_instance_get_guid (QOF_INSTANCE(account))));
- amount = gncTaxTableEntryGetAmount (entry);
- xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount));
+ amount = gncTaxTableEntryGetAmount (entry);
+ xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount));
- xmlAddChild(ret, text_to_dom_tree (ttentry_type_string,
- gncAmountTypeToString (
- gncTaxTableEntryGetType (entry))));
+ xmlAddChild(ret, text_to_dom_tree (ttentry_type_string,
+ gncAmountTypeToString (
+ gncTaxTableEntryGetType (entry))));
- return ret;
+ return ret;
}
static xmlNodePtr
@@ -110,23 +110,24 @@
maybe_add_guid(ret, taxtable_guid_string, table);
xmlAddChild(ret, text_to_dom_tree (taxtable_name_string,
- gncTaxTableGetName (table)));
+ gncTaxTableGetName (table)));
xmlAddChild(ret, int_to_dom_tree (taxtable_refcount_string,
- gncTaxTableGetRefcount (table)));
+ gncTaxTableGetRefcount (table)));
xmlAddChild(ret, int_to_dom_tree (taxtable_invisible_string,
- gncTaxTableGetInvisible (table)));
+ gncTaxTableGetInvisible (table)));
/* We should not be our own child */
if (gncTaxTableGetChild(table) != table)
- maybe_add_guid(ret, taxtable_child_string, gncTaxTableGetChild (table));
+ maybe_add_guid(ret, taxtable_child_string, gncTaxTableGetChild (table));
maybe_add_guid(ret, taxtable_parent_string, gncTaxTableGetParent (table));
entries = xmlNewChild (ret, NULL, BAD_CAST taxtable_entries_string, NULL);
- for (list = gncTaxTableGetEntries (table); list; list = list->next) {
- GncTaxTableEntry *entry = list->data;
- xmlAddChild(entries, ttentry_dom_tree_create (entry));
+ for (list = gncTaxTableGetEntries (table); list; list = list->next)
+ {
+ GncTaxTableEntry *entry = list->data;
+ xmlAddChild(entries, ttentry_dom_tree_create (entry));
}
return ret;
@@ -136,123 +137,127 @@
struct ttentry_pdata
{
- GncTaxTableEntry *ttentry;
- QofBook *book;
+ GncTaxTableEntry *ttentry;
+ QofBook *book;
};
static gboolean
ttentry_acct_handler (xmlNodePtr node, gpointer ttentry_pdata)
{
- struct ttentry_pdata *pdata = ttentry_pdata;
- GUID *guid;
- Account * acc;
+ struct ttentry_pdata *pdata = ttentry_pdata;
+ GUID *guid;
+ Account * acc;
- guid = dom_tree_to_guid (node);
- g_return_val_if_fail (guid, FALSE);
- acc = xaccAccountLookup (guid, pdata->book);
- g_free (guid);
- g_return_val_if_fail (acc, FALSE);
+ guid = dom_tree_to_guid (node);
+ g_return_val_if_fail (guid, FALSE);
+ acc = xaccAccountLookup (guid, pdata->book);
+ g_free (guid);
+ g_return_val_if_fail (acc, FALSE);
- gncTaxTableEntrySetAccount (pdata->ttentry, acc);
- return TRUE;
+ gncTaxTableEntrySetAccount (pdata->ttentry, acc);
+ return TRUE;
}
static gboolean
ttentry_type_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct ttentry_pdata *pdata = taxtable_pdata;
- GncAmountType type;
- char *str;
- gboolean ret;
+ struct ttentry_pdata *pdata = taxtable_pdata;
+ GncAmountType type;
+ char *str;
+ gboolean ret;
- str = dom_tree_to_text (node);
- g_return_val_if_fail (str, FALSE);
+ str = dom_tree_to_text (node);
+ g_return_val_if_fail (str, FALSE);
- ret = gncAmountStringToType (str, &type);
- g_free (str);
+ ret = gncAmountStringToType (str, &type);
+ g_free (str);
- if (ret)
- gncTaxTableEntrySetType (pdata->ttentry, type);
+ if (ret)
+ gncTaxTableEntrySetType (pdata->ttentry, type);
- return ret;
+ return ret;
}
static gboolean
ttentry_amount_handler (xmlNodePtr node, gpointer ttentry_pdata)
{
- struct ttentry_pdata *pdata = ttentry_pdata;
- gnc_numeric* num = dom_tree_to_gnc_numeric(node);
- g_return_val_if_fail(num, FALSE);
-
- gncTaxTableEntrySetAmount (pdata->ttentry, *num);
- g_free(num);
- return TRUE;
+ struct ttentry_pdata *pdata = ttentry_pdata;
+ gnc_numeric* num = dom_tree_to_gnc_numeric(node);
+ g_return_val_if_fail(num, FALSE);
+
+ gncTaxTableEntrySetAmount (pdata->ttentry, *num);
+ g_free(num);
+ return TRUE;
}
-static struct dom_tree_handler ttentry_handlers_v2[] = {
- { ttentry_account_string, ttentry_acct_handler, 0, 0 },
- { ttentry_type_string, ttentry_type_handler, 1, 0 },
- { ttentry_amount_string, ttentry_amount_handler, 1, 0 },
- { NULL, 0, 0, 0 }
+static struct dom_tree_handler ttentry_handlers_v2[] =
+{
+ { ttentry_account_string, ttentry_acct_handler, 0, 0 },
+ { ttentry_type_string, ttentry_type_handler, 1, 0 },
+ { ttentry_amount_string, ttentry_amount_handler, 1, 0 },
+ { NULL, 0, 0, 0 }
};
static GncTaxTableEntry*
dom_tree_to_ttentry (xmlNodePtr node, QofBook *book)
{
- struct ttentry_pdata ttentry_pdata;
- gboolean successful;
-
- ttentry_pdata.ttentry = gncTaxTableEntryCreate ();
- ttentry_pdata.book = book;
+ struct ttentry_pdata ttentry_pdata;
+ gboolean successful;
- successful = dom_tree_generic_parse (node, ttentry_handlers_v2,
- &ttentry_pdata);
+ ttentry_pdata.ttentry = gncTaxTableEntryCreate ();
+ ttentry_pdata.book = book;
- if (!successful) {
- PERR ("failed to parse tax table entry tree");
- gncTaxTableEntryDestroy (ttentry_pdata.ttentry);
- ttentry_pdata.ttentry = NULL;
- }
+ successful = dom_tree_generic_parse (node, ttentry_handlers_v2,
+ &ttentry_pdata);
- return ttentry_pdata.ttentry;
+ if (!successful)
+ {
+ PERR ("failed to parse tax table entry tree");
+ gncTaxTableEntryDestroy (ttentry_pdata.ttentry);
+ ttentry_pdata.ttentry = NULL;
+ }
+
+ return ttentry_pdata.ttentry;
}
/***********************************************************************/
struct taxtable_pdata
{
- GncTaxTable *table;
- QofBook *book;
+ GncTaxTable *table;
+ QofBook *book;
};
static gboolean
set_parent_child (xmlNodePtr node, struct taxtable_pdata *pdata,
- void (*func)(GncTaxTable *, GncTaxTable *))
+ void (*func)(GncTaxTable *, GncTaxTable *))
{
- GUID *guid;
- GncTaxTable *table;
+ GUID *guid;
+ GncTaxTable *table;
- guid = dom_tree_to_guid(node);
- g_return_val_if_fail (guid, FALSE);
- table = gncTaxTableLookup (pdata->book, guid);
+ guid = dom_tree_to_guid(node);
+ g_return_val_if_fail (guid, FALSE);
+ table = gncTaxTableLookup (pdata->book, guid);
- /* Ignore pointers to self */
- if (table == pdata->table) {
- PINFO ("found a self-referential parent/child; ignoring.\n");
- return TRUE;
- }
+ /* Ignore pointers to self */
+ if (table == pdata->table)
+ {
+ PINFO ("found a self-referential parent/child; ignoring.\n");
+ return TRUE;
+ }
- if (!table) {
- table = gncTaxTableCreate (pdata->book);
- gncTaxTableBeginEdit (table);
- gncTaxTableSetGUID (table, guid);
- gncTaxTableCommitEdit (table);
- }
- g_free (guid);
- g_return_val_if_fail (table, FALSE);
- func (pdata->table, table);
+ if (!table)
+ {
+ table = gncTaxTableCreate (pdata->book);
+ gncTaxTableBeginEdit (table);
+ gncTaxTableSetGUID (table, guid);
+ gncTaxTableCommitEdit (table);
+ }
+ g_free (guid);
+ g_return_val_if_fail (table, FALSE);
+ func (pdata->table, table);
- return TRUE;
+ return TRUE;
}
static gboolean
@@ -265,104 +270,109 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE);
table = gncTaxTableLookup (pdata->book, guid);
- if (table) {
- gncTaxTableDestroy (pdata->table);
- pdata->table = table;
- gncTaxTableBeginEdit (table);
- } else {
- gncTaxTableSetGUID(pdata->table, guid);
+ if (table)
+ {
+ gncTaxTableDestroy (pdata->table);
+ pdata->table = table;
+ gncTaxTableBeginEdit (table);
}
+ else
+ {
+ gncTaxTableSetGUID(pdata->table, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
static gboolean
taxtable_name_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- gncTaxTableSetName (pdata->table, txt);
- g_free(txt);
- return TRUE;
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ gncTaxTableSetName (pdata->table, txt);
+ g_free(txt);
+ return TRUE;
}
static gboolean
taxtable_refcount_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- gint64 val;
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ gint64 val;
- dom_tree_to_integer(node, &val);
- gncTaxTableSetRefcount (pdata->table, val);
- return TRUE;
+ dom_tree_to_integer(node, &val);
+ gncTaxTableSetRefcount (pdata->table, val);
+ return TRUE;
}
static gboolean
taxtable_invisible_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- gint64 val;
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ gint64 val;
- dom_tree_to_integer(node, &val);
- if (val)
- gncTaxTableMakeInvisible (pdata->table);
- return TRUE;
+ dom_tree_to_integer(node, &val);
+ if (val)
+ gncTaxTableMakeInvisible (pdata->table);
+ return TRUE;
}
static gboolean
taxtable_parent_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- return set_parent_child (node, pdata, gncTaxTableSetParent);
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ return set_parent_child (node, pdata, gncTaxTableSetParent);
}
static gboolean
taxtable_child_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- return set_parent_child (node, pdata, gncTaxTableSetChild);
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ return set_parent_child (node, pdata, gncTaxTableSetChild);
}
static gboolean
taxtable_entries_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- struct taxtable_pdata *pdata = taxtable_pdata;
- xmlNodePtr mark;
+ struct taxtable_pdata *pdata = taxtable_pdata;
+ xmlNodePtr mark;
- g_return_val_if_fail (node, FALSE);
- g_return_val_if_fail (node->xmlChildrenNode, FALSE);
+ g_return_val_if_fail (node, FALSE);
+ g_return_val_if_fail (node->xmlChildrenNode, FALSE);
- for (mark = node->xmlChildrenNode; mark; mark = mark->next) {
- GncTaxTableEntry *entry;
-
- if (safe_strcmp ("text", (char*)mark->name) == 0)
- continue;
+ for (mark = node->xmlChildrenNode; mark; mark = mark->next)
+ {
+ GncTaxTableEntry *entry;
- if (safe_strcmp (gnc_taxtableentry_string, (char*)mark->name))
- return FALSE;
+ if (safe_strcmp ("text", (char*)mark->name) == 0)
+ continue;
- entry = dom_tree_to_ttentry (mark, pdata->book);
+ if (safe_strcmp (gnc_taxtableentry_string, (char*)mark->name))
+ return FALSE;
- if (entry)
- gncTaxTableAddEntry (pdata->table, entry);
- else
- return FALSE;
+ entry = dom_tree_to_ttentry (mark, pdata->book);
- }
- return TRUE;
+ if (entry)
+ gncTaxTableAddEntry (pdata->table, entry);
+ else
+ return FALSE;
+
+ }
+ return TRUE;
}
static gboolean
taxtable_slots_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
- return TRUE;
+ return TRUE;
}
-static struct dom_tree_handler taxtable_handlers_v2[] = {
+static struct dom_tree_handler taxtable_handlers_v2[] =
+{
{ taxtable_guid_string, taxtable_guid_handler, 1, 0 },
{ taxtable_name_string, taxtable_name_handler, 1, 0 },
{ taxtable_refcount_string, taxtable_refcount_handler, 1, 0 },
@@ -377,33 +387,33 @@
static GncTaxTable*
dom_tree_to_taxtable (xmlNodePtr node, QofBook *book)
{
- struct taxtable_pdata taxtable_pdata;
- gboolean successful;
-
- taxtable_pdata.table = gncTaxTableCreate (book);
- taxtable_pdata.book = book;
- gncTaxTableBeginEdit (taxtable_pdata.table);
+ struct taxtable_pdata taxtable_pdata;
+ gboolean successful;
- successful = dom_tree_generic_parse (node, taxtable_handlers_v2,
- &taxtable_pdata);
+ taxtable_pdata.table = gncTaxTableCreate (book);
+ taxtable_pdata.book = book;
+ gncTaxTableBeginEdit (taxtable_pdata.table);
- if (successful)
- gncTaxTableCommitEdit (taxtable_pdata.table);
- else
- {
- PERR ("failed to parse tax table tree");
- gncTaxTableDestroy (taxtable_pdata.table);
- taxtable_pdata.table = NULL;
- }
+ successful = dom_tree_generic_parse (node, taxtable_handlers_v2,
+ &taxtable_pdata);
- return taxtable_pdata.table;
+ if (successful)
+ gncTaxTableCommitEdit (taxtable_pdata.table);
+ else
+ {
+ PERR ("failed to parse tax table tree");
+ gncTaxTableDestroy (taxtable_pdata.table);
+ taxtable_pdata.table = NULL;
+ }
+
+ return taxtable_pdata.table;
}
static gboolean
gnc_taxtable_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncTaxTable *table;
@@ -413,14 +423,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -428,7 +438,7 @@
g_return_val_if_fail(tree, FALSE);
table = dom_tree_to_taxtable (tree, book);
- if(table != NULL)
+ if (table != NULL)
{
gdata->cb(tag, gdata->parsedata, table);
}
@@ -441,97 +451,99 @@
static sixtp *
taxtable_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_taxtable_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_taxtable_end_handler, NULL, NULL);
}
static void
do_count (QofInstance * table_p, gpointer count_p)
{
- int *count = count_p;
- (*count)++;
+ int *count = count_p;
+ (*count)++;
}
static int
taxtable_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_taxtable (QofInstance * table_p, gpointer out_p)
{
- xmlNodePtr node;
- GncTaxTable *table = (GncTaxTable *) table_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncTaxTable *table = (GncTaxTable *) table_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
+ if (ferror(out))
+ return;
- node = taxtable_dom_tree_create (table);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = taxtable_dom_tree_create (table);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
taxtable_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
taxtable_is_grandchild (GncTaxTable *table)
{
- return (gncTaxTableGetParent(gncTaxTableGetParent(table)) != NULL);
+ return (gncTaxTableGetParent(gncTaxTableGetParent(table)) != NULL);
}
static GncTaxTable *
taxtable_find_senior (GncTaxTable *table)
{
- GncTaxTable *temp, *parent, *gp = NULL;
+ GncTaxTable *temp, *parent, *gp = NULL;
- temp = table;
- do {
- /* See if "temp" is a grandchild */
- parent = gncTaxTableGetParent(temp);
- if (!parent)
- break;
- gp = gncTaxTableGetParent(parent);
- if (!gp)
- break;
+ temp = table;
+ do
+ {
+ /* See if "temp" is a grandchild */
+ parent = gncTaxTableGetParent(temp);
+ if (!parent)
+ break;
+ gp = gncTaxTableGetParent(parent);
+ if (!gp)
+ break;
- /* Yep, this is a grandchild. Move up one generation and try again */
- temp = parent;
- } while (TRUE);
+ /* Yep, this is a grandchild. Move up one generation and try again */
+ temp = parent;
+ }
+ while (TRUE);
- /* Ok, at this point temp points to the most senior child and parent
- * should point to the top taxtable (and gp should be NULL). If
- * parent is NULL then we are the most senior child (and have no
- * children), so do nothing. If temp == table then there is no
- * grandparent, so do nothing.
- *
- * Do something if parent != NULL && temp != table
- */
- g_assert (gp == NULL);
+ /* Ok, at this point temp points to the most senior child and parent
+ * should point to the top taxtable (and gp should be NULL). If
+ * parent is NULL then we are the most senior child (and have no
+ * children), so do nothing. If temp == table then there is no
+ * grandparent, so do nothing.
+ *
+ * Do something if parent != NULL && temp != table
+ */
+ g_assert (gp == NULL);
- /* return the most senior table */
- return temp;
+ /* return the most senior table */
+ return temp;
}
/* build a list of tax tables that are grandchildren or bogus (empty entry list). */
static void
taxtable_scrub_cb (QofInstance * table_p, gpointer list_p)
{
- GncTaxTable *table = GNC_TAXTABLE(table_p);
- GList **list = list_p;
+ GncTaxTable *table = GNC_TAXTABLE(table_p);
+ GList **list = list_p;
- if (taxtable_is_grandchild(table) || gncTaxTableGetEntries(table) == NULL)
- *list = g_list_prepend(*list, table);
+ if (taxtable_is_grandchild(table) || gncTaxTableGetEntries(table) == NULL)
+ *list = g_list_prepend(*list, table);
}
/* for each entry, check the tax tables. If the tax tables are
@@ -540,154 +552,165 @@
static void
taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncEntry *entry = GNC_ENTRY(entry_p);
- GncTaxTable *table, *new_tt;
- gint32 count;
+ GHashTable *ht = ht_p;
+ GncEntry *entry = GNC_ENTRY(entry_p);
+ GncTaxTable *table, *new_tt;
+ gint32 count;
- table = gncEntryGetInvTaxTable(entry);
- if (table) {
- if (taxtable_is_grandchild(table)) {
- PINFO("Fixing i-taxtable on entry %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
- new_tt = taxtable_find_senior(table);
- gncEntryBeginEdit(entry);
- gncEntrySetInvTaxTable(entry, new_tt);
- gncEntryCommitEdit(entry);
- table = new_tt;
+ table = gncEntryGetInvTaxTable(entry);
+ if (table)
+ {
+ if (taxtable_is_grandchild(table))
+ {
+ PINFO("Fixing i-taxtable on entry %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
+ new_tt = taxtable_find_senior(table);
+ gncEntryBeginEdit(entry);
+ gncEntrySetInvTaxTable(entry, new_tt);
+ gncEntryCommitEdit(entry);
+ table = new_tt;
+ }
+ if (table)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
+ count++;
+ g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
+ }
}
- if (table) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
- count++;
- g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
- }
- }
- table = gncEntryGetBillTaxTable(entry);
- if (table) {
- if (taxtable_is_grandchild(table)) {
- PINFO("Fixing b-taxtable on entry %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
- new_tt = taxtable_find_senior(table);
- gncEntryBeginEdit(entry);
- gncEntrySetBillTaxTable(entry, new_tt);
- gncEntryCommitEdit(entry);
- table = new_tt;
+ table = gncEntryGetBillTaxTable(entry);
+ if (table)
+ {
+ if (taxtable_is_grandchild(table))
+ {
+ PINFO("Fixing b-taxtable on entry %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
+ new_tt = taxtable_find_senior(table);
+ gncEntryBeginEdit(entry);
+ gncEntrySetBillTaxTable(entry, new_tt);
+ gncEntryCommitEdit(entry);
+ table = new_tt;
+ }
+ if (table)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
+ count++;
+ g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
+ }
}
- if (table) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
- count++;
- g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
- }
- }
}
static void
taxtable_scrub_cust (QofInstance * cust_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncCustomer *cust = GNC_CUSTOMER(cust_p);
- GncTaxTable *table;
- gint32 count;
-
- table = gncCustomerGetTaxTable(cust);
- if (table) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
- count++;
- g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
- }
+ GHashTable *ht = ht_p;
+ GncCustomer *cust = GNC_CUSTOMER(cust_p);
+ GncTaxTable *table;
+ gint32 count;
+
+ table = gncCustomerGetTaxTable(cust);
+ if (table)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
+ count++;
+ g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
+ }
}
static void
taxtable_scrub_vendor (QofInstance * vendor_p, gpointer ht_p)
{
- GHashTable *ht = ht_p;
- GncVendor *vendor = GNC_VENDOR(vendor_p);
- GncTaxTable *table;
- gint32 count;
+ GHashTable *ht = ht_p;
+ GncVendor *vendor = GNC_VENDOR(vendor_p);
+ GncTaxTable *table;
+ gint32 count;
- table = gncVendorGetTaxTable(vendor);
- if (table) {
- count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
- count++;
- g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
- }
+ table = gncVendorGetTaxTable(vendor);
+ if (table)
+ {
+ count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
+ count++;
+ g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
+ }
}
static void
taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused)
{
- GncTaxTable *table = key;
- gint32 count = GPOINTER_TO_INT(value);
+ GncTaxTable *table = key;
+ gint32 count = GPOINTER_TO_INT(value);
- if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table)) {
- PWARN("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))),
- gncTaxTableGetRefcount(table), count);
- gncTaxTableSetRefcount(table, count);
- }
+ if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table))
+ {
+ PWARN("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))),
+ gncTaxTableGetRefcount(table), count);
+ gncTaxTableSetRefcount(table, count);
+ }
}
static void
taxtable_scrub (QofBook *book)
{
- GList *list = NULL;
- GList *node;
- GncTaxTable *parent, *table;
- GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
+ GList *list = NULL;
+ GList *node;
+ GncTaxTable *parent, *table;
+ GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
- qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
- qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
- qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
- qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);
+ qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
+ qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
+ qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
+ qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);
- /* destroy the list of "grandchildren" tax tables */
- for (node = list; node; node = node->next) {
- table = node->data;
+ /* destroy the list of "grandchildren" tax tables */
+ for (node = list; node; node = node->next)
+ {
+ table = node->data;
- PINFO ("deleting grandchild taxtable: %s\n",
- guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))));
+ PINFO ("deleting grandchild taxtable: %s\n",
+ guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))));
- /* Make sure the parent has no children */
- parent = gncTaxTableGetParent(table);
- gncTaxTableSetChild(parent, NULL);
+ /* Make sure the parent has no children */
+ parent = gncTaxTableGetParent(table);
+ gncTaxTableSetChild(parent, NULL);
- /* Destroy this tax table */
- gncTaxTableBeginEdit(table);
- gncTaxTableDestroy(table);
- }
+ /* Destroy this tax table */
+ gncTaxTableBeginEdit(table);
+ gncTaxTableDestroy(table);
+ }
- /* reset the refcounts as necessary */
- g_hash_table_foreach(ht, taxtable_reset_refcount, NULL);
+ /* reset the refcounts as necessary */
+ g_hash_table_foreach(ht, taxtable_reset_refcount, NULL);
- g_list_free(list);
- g_hash_table_destroy(ht);
+ g_list_free(list);
+ g_hash_table_destroy(ht);
}
static gboolean
taxtable_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return
- gnc_xml2_write_namespace_decl(out, "taxtable")
- && gnc_xml2_write_namespace_decl(out, "tte");
+ g_return_val_if_fail(out, FALSE);
+ return
+ gnc_xml2_write_namespace_decl(out, "taxtable")
+ && gnc_xml2_write_namespace_decl(out, "tte");
}
void
gnc_taxtable_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_taxtable_string,
- taxtable_sixtp_parser_create,
- NULL, /* add_item */
- taxtable_get_count,
- taxtable_write,
- taxtable_scrub,
- taxtable_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_taxtable_string,
+ taxtable_sixtp_parser_create,
+ NULL, /* add_item */
+ taxtable_get_count,
+ taxtable_write,
+ taxtable_scrub,
+ taxtable_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/gnc-vendor-xml-v2.c
===================================================================
--- gnucash/trunk/src/business/business-core/xml/gnc-vendor-xml-v2.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/gnc-vendor-xml-v2.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -81,45 +81,45 @@
xmlSetProp(ret, BAD_CAST "version", BAD_CAST vendor_version_string);
xmlAddChild(ret, guid_to_dom_tree(vendor_guid_string,
- qof_instance_get_guid (QOF_INSTANCE(vendor))));
+ qof_instance_get_guid (QOF_INSTANCE(vendor))));
xmlAddChild(ret, text_to_dom_tree(vendor_name_string,
gncVendorGetName (vendor)));
-
+
xmlAddChild(ret, text_to_dom_tree(vendor_id_string,
gncVendorGetID (vendor)));
xmlAddChild(ret, gnc_address_to_dom_tree(vendor_addr_string,
- gncVendorGetAddr (vendor)));
-
+ gncVendorGetAddr (vendor)));
+
maybe_add_string (ret, vendor_notes_string, gncVendorGetNotes (vendor));
term = gncVendorGetTerms (vendor);
if (term)
- xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string,
- qof_instance_get_guid(QOF_INSTANCE(term))));
+ xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string,
+ qof_instance_get_guid(QOF_INSTANCE(term))));
xmlAddChild(ret, text_to_dom_tree(vendor_taxincluded_string,
- gncTaxIncludedTypeToString (
- gncVendorGetTaxIncluded (vendor))));
+ gncTaxIncludedTypeToString (
+ gncVendorGetTaxIncluded (vendor))));
xmlAddChild(ret, int_to_dom_tree(vendor_active_string,
- gncVendorGetActive (vendor)));
+ gncVendorGetActive (vendor)));
xmlAddChild
- (ret,
- commodity_ref_to_dom_tree(vendor_currency_string,
- gncVendorGetCurrency (vendor)));
+ (ret,
+ commodity_ref_to_dom_tree(vendor_currency_string,
+ gncVendorGetCurrency (vendor)));
xmlAddChild (ret, int_to_dom_tree (vendor_taxtableoverride_string,
- gncVendorGetTaxTableOverride (vendor)));
+ gncVendorGetTaxTableOverride (vendor)));
taxtable = gncVendorGetTaxTable (vendor);
if (taxtable)
- xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
- qof_instance_get_guid(QOF_INSTANCE(taxtable))));
+ xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
+ qof_instance_get_guid(QOF_INSTANCE(taxtable))));
- kvpnode = kvp_frame_to_dom_tree (vendor_slots_string,
- qof_instance_get_slots (QOF_INSTANCE(vendor)));
+ kvpnode = kvp_frame_to_dom_tree (vendor_slots_string,
+ qof_instance_get_slots (QOF_INSTANCE(vendor)));
if (kvpnode) xmlAddChild (ret, kvpnode);
return ret;
@@ -129,34 +129,34 @@
struct vendor_pdata
{
- GncVendor *vendor;
- QofBook *book;
+ GncVendor *vendor;
+ QofBook *book;
};
static gboolean
set_string(xmlNodePtr node, GncVendor* vendor,
void (*func)(GncVendor *vendor, const char *txt))
{
- char* txt = dom_tree_to_text(node);
- g_return_val_if_fail(txt, FALSE);
-
- func(vendor, txt);
-
- g_free(txt);
-
- return TRUE;
+ char* txt = dom_tree_to_text(node);
+ g_return_val_if_fail(txt, FALSE);
+
+ func(vendor, txt);
+
+ g_free(txt);
+
+ return TRUE;
}
static gboolean
set_boolean(xmlNodePtr node, GncVendor* vendor,
- void (*func)(GncVendor* vendor, gboolean b))
+ void (*func)(GncVendor* vendor, gboolean b))
{
gint64 val;
gboolean ret;
ret = dom_tree_to_integer(node, &val);
if (ret)
- func(vendor, (gboolean)val);
+ func(vendor, (gboolean)val);
return ret;
}
@@ -179,16 +179,19 @@
guid = dom_tree_to_guid(node);
g_return_val_if_fail(guid, FALSE);
vendor = gncVendorLookup (pdata->book, guid);
- if (vendor) {
- gncVendorDestroy (pdata->vendor);
- pdata->vendor = vendor;
- gncVendorBeginEdit (vendor);
- } else {
- gncVendorSetGUID(pdata->vendor, guid);
+ if (vendor)
+ {
+ gncVendorDestroy (pdata->vendor);
+ pdata->vendor = vendor;
+ gncVendorBeginEdit (vendor);
}
+ else
+ {
+ gncVendorSetGUID(pdata->vendor, guid);
+ }
g_free(guid);
-
+
return TRUE;
}
@@ -221,7 +224,7 @@
g_assert(term);
g_free (guid);
gncVendorSetTerms (pdata->vendor, term);
-
+
return TRUE;
}
@@ -248,7 +251,7 @@
g_free (str);
if (ret)
- gncVendorSetTaxIncluded(pdata->vendor, type);
+ gncVendorSetTaxIncluded(pdata->vendor, type);
return ret;
}
@@ -284,13 +287,15 @@
guid = dom_tree_to_guid (node);
g_return_val_if_fail (guid, FALSE);
taxtable = gncTaxTableLookup (pdata->book, guid);
- if (!taxtable) {
- taxtable = gncTaxTableCreate (pdata->book);
- gncTaxTableBeginEdit (taxtable);
- gncTaxTableSetGUID (taxtable, guid);
- gncTaxTableCommitEdit (taxtable);
- } else
- gncTaxTableDecRef (taxtable);
+ if (!taxtable)
+ {
+ taxtable = gncTaxTableCreate (pdata->book);
+ gncTaxTableBeginEdit (taxtable);
+ gncTaxTableSetGUID (taxtable, guid);
+ gncTaxTableCommitEdit (taxtable);
+ }
+ else
+ gncTaxTableDecRef (taxtable);
gncVendorSetTaxTable (pdata->vendor, taxtable);
g_free(guid);
@@ -309,11 +314,12 @@
{
struct vendor_pdata *pdata = vendor_pdata;
return dom_tree_to_kvp_frame_given (
- node, qof_instance_get_slots (QOF_INSTANCE(pdata->vendor)));
+ node, qof_instance_get_slots (QOF_INSTANCE(pdata->vendor)));
}
-static struct dom_tree_handler vendor_handlers_v2[] = {
+static struct dom_tree_handler vendor_handlers_v2[] =
+{
{ vendor_name_string, vendor_name_handler, 1, 0 },
{ vendor_guid_string, vendor_guid_handler, 1, 0 },
{ vendor_id_string, vendor_id_handler, 1, 0 },
@@ -344,7 +350,7 @@
&vendor_pdata);
if (successful)
- gncVendorCommitEdit (vendor_pdata.vendor);
+ gncVendorCommitEdit (vendor_pdata.vendor);
else
{
PERR ("failed to parse vendor tree");
@@ -357,9 +363,9 @@
static gboolean
gnc_vendor_end_handler(gpointer data_for_children,
- GSList* data_from_children, GSList* sibling_data,
- gpointer parent_data, gpointer global_data,
- gpointer *result, const gchar *tag)
+ GSList* data_from_children, GSList* sibling_data,
+ gpointer parent_data, gpointer global_data,
+ gpointer *result, const gchar *tag)
{
int successful;
GncVendor *vendor;
@@ -369,14 +375,14 @@
successful = TRUE;
- if(parent_data)
+ if (parent_data)
{
return TRUE;
}
/* OK. For some messed up reason this is getting called again with a
NULL tag. So we ignore those cases */
- if(!tag)
+ if (!tag)
{
return TRUE;
}
@@ -384,7 +390,7 @@
g_return_val_if_fail(tree, FALSE);
vendor = dom_tree_to_vendor(tree, book);
- if(vendor != NULL)
+ if (vendor != NULL)
{
gdata->cb(tag, gdata->parsedata, vendor);
}
@@ -397,86 +403,87 @@
static sixtp *
vendor_sixtp_parser_create(void)
{
- return sixtp_dom_parser_new(gnc_vendor_end_handler, NULL, NULL);
+ return sixtp_dom_parser_new(gnc_vendor_end_handler, NULL, NULL);
}
static gboolean
vendor_should_be_saved (GncVendor *vendor)
{
- const char *id;
+ const char *id;
- /* make sure this is a valid vendor before we save it -- should have an ID */
- id = gncVendorGetID (vendor);
- if (id == NULL || *id == '\0')
- return FALSE;
+ /* make sure this is a valid vendor before we save it -- should have an ID */
+ id = gncVendorGetID (vendor);
+ if (id == NULL || *id == '\0')
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
do_count (QofInstance * vendor_p, gpointer count_p)
{
- int *count = count_p;
- if (vendor_should_be_saved ((GncVendor *)vendor_p))
- (*count)++;
+ int *count = count_p;
+ if (vendor_should_be_saved ((GncVendor *)vendor_p))
+ (*count)++;
}
static int
vendor_get_count (QofBook *book)
{
- int count = 0;
- qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
- return count;
+ int count = 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
+ return count;
}
static void
xml_add_vendor (QofInstance * vendor_p, gpointer out_p)
{
- xmlNodePtr node;
- GncVendor *vendor = (GncVendor *) vendor_p;
- FILE *out = out_p;
+ xmlNodePtr node;
+ GncVendor *vendor = (GncVendor *) vendor_p;
+ FILE *out = out_p;
- if (ferror(out))
- return;
- if (!vendor_should_be_saved (vendor))
- return;
+ if (ferror(out))
+ return;
+ if (!vendor_should_be_saved (vendor))
+ return;
- node = vendor_dom_tree_create (vendor);
- xmlElemDump(out, NULL, node);
- xmlFreeNode (node);
- if (ferror(out) || fprintf(out, "\n") < 0)
- return;
+ node = vendor_dom_tree_create (vendor);
+ xmlElemDump(out, NULL, node);
+ xmlFreeNode (node);
+ if (ferror(out) || fprintf(out, "\n") < 0)
+ return;
}
static gboolean
vendor_write (FILE *out, QofBook *book)
{
- qof_object_foreach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out);
- return ferror(out) == 0;
+ qof_object_foreach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out);
+ return ferror(out) == 0;
}
static gboolean
vendor_ns(FILE *out)
{
- g_return_val_if_fail(out, FALSE);
- return gnc_xml2_write_namespace_decl(out, "vendor");
+ g_return_val_if_fail(out, FALSE);
+ return gnc_xml2_write_namespace_decl(out, "vendor");
}
void
gnc_vendor_xml_initialize (void)
{
- static GncXmlDataType_t be_data = {
- GNC_FILE_BACKEND_VERS,
- gnc_vendor_string,
- vendor_sixtp_parser_create,
- NULL, /* add_item */
- vendor_get_count,
- vendor_write,
- NULL, /* scrub */
- vendor_ns,
- };
+ static GncXmlDataType_t be_data =
+ {
+ GNC_FILE_BACKEND_VERS,
+ gnc_vendor_string,
+ vendor_sixtp_parser_create,
+ NULL, /* add_item */
+ vendor_get_count,
+ vendor_write,
+ NULL, /* scrub */
+ vendor_ns,
+ };
- qof_object_register_backend (_GNC_MOD_NAME,
- GNC_FILE_BACKEND,
- &be_data);
+ qof_object_register_backend (_GNC_MOD_NAME,
+ GNC_FILE_BACKEND,
+ &be_data);
}
Modified: gnucash/trunk/src/business/business-core/xml/xml-helpers.h
===================================================================
--- gnucash/trunk/src/business/business-core/xml/xml-helpers.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-core/xml/xml-helpers.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -6,29 +6,29 @@
static inline void
maybe_add_int (xmlNodePtr ptr, const char *tag, gint val)
{
- if (val)
- xmlAddChild (ptr, int_to_dom_tree (tag, val));
+ if (val)
+ xmlAddChild (ptr, int_to_dom_tree (tag, val));
}
static inline void
maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric val)
{
- if (!gnc_numeric_zero_p (val))
- xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &val));
+ if (!gnc_numeric_zero_p (val))
+ xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &val));
}
static inline void
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
{
- if (str && strlen(str) > 0)
- xmlAddChild (ptr, text_to_dom_tree (tag, str));
+ if (str && strlen(str) > 0)
+ xmlAddChild (ptr, text_to_dom_tree (tag, str));
}
static inline void
maybe_add_guid (xmlNodePtr ptr, const char *tag, QofInstance *inst)
{
- if (inst)
- xmlAddChild (ptr, guid_to_dom_tree (tag,
- qof_instance_get_guid (inst)));
+ if (inst)
+ xmlAddChild (ptr, guid_to_dom_tree (tag,
+ qof_instance_get_guid (inst)));
}
Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -51,344 +51,357 @@
#include "gnc-commodity.h"
-typedef enum {
- GNCSEARCH_TYPE_SELECT,
- GNCSEARCH_TYPE_EDIT
+typedef enum
+{
+ GNCSEARCH_TYPE_SELECT,
+ GNCSEARCH_TYPE_EDIT
} GNCSearchType;
static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox,
- QofBook *book, GncOwner *owner,
- GNCSearchType type)
+ QofBook *book, GncOwner *owner,
+ GNCSearchType type)
{
- GtkWidget *edit;
- GNCSearchCB search_cb = NULL;
- const char *type_name = NULL;
- const char *text = NULL;
- gboolean text_editable = FALSE;
+ GtkWidget *edit;
+ GNCSearchCB search_cb = NULL;
+ const char *type_name = NULL;
+ const char *text = NULL;
+ gboolean text_editable = FALSE;
- switch (type) {
- case GNCSEARCH_TYPE_SELECT:
- text = _("Select...");
- text_editable = TRUE;
- break;
- case GNCSEARCH_TYPE_EDIT:
- text = _("Edit...");
- text_editable = FALSE;
- };
+ switch (type)
+ {
+ case GNCSEARCH_TYPE_SELECT:
+ text = _("Select...");
+ text_editable = TRUE;
+ break;
+ case GNCSEARCH_TYPE_EDIT:
+ text = _("Edit...");
+ text_editable = FALSE;
+ };
- switch (owner->type) {
- case GNC_OWNER_NONE:
- case GNC_OWNER_UNDEFINED:
- return NULL;
+ switch (owner->type)
+ {
+ case GNC_OWNER_NONE:
+ case GNC_OWNER_UNDEFINED:
+ return NULL;
- case GNC_OWNER_CUSTOMER:
- if (type == GNCSEARCH_TYPE_SELECT)
- search_cb = gnc_customer_search_select;
- else
- search_cb = gnc_customer_search_edit;
- type_name = GNC_CUSTOMER_MODULE_NAME;
- break;
+ case GNC_OWNER_CUSTOMER:
+ if (type == GNCSEARCH_TYPE_SELECT)
+ search_cb = gnc_customer_search_select;
+ else
+ search_cb = gnc_customer_search_edit;
+ type_name = GNC_CUSTOMER_MODULE_NAME;
+ break;
- case GNC_OWNER_JOB:
- if (type == GNCSEARCH_TYPE_SELECT)
- search_cb = gnc_job_search_select;
- else
- search_cb = gnc_job_search_edit;
- type_name = GNC_JOB_MODULE_NAME;
- break;
+ case GNC_OWNER_JOB:
+ if (type == GNCSEARCH_TYPE_SELECT)
+ search_cb = gnc_job_search_select;
+ else
+ search_cb = gnc_job_search_edit;
+ type_name = GNC_JOB_MODULE_NAME;
+ break;
- case GNC_OWNER_VENDOR:
- if (type == GNCSEARCH_TYPE_SELECT)
- search_cb = gnc_vendor_search_select;
- else
- search_cb = gnc_vendor_search_edit;
- type_name = GNC_VENDOR_MODULE_NAME;
- break;
+ case GNC_OWNER_VENDOR:
+ if (type == GNCSEARCH_TYPE_SELECT)
+ search_cb = gnc_vendor_search_select;
+ else
+ search_cb = gnc_vendor_search_edit;
+ type_name = GNC_VENDOR_MODULE_NAME;
+ break;
- case GNC_OWNER_EMPLOYEE:
- if (type == GNCSEARCH_TYPE_SELECT)
- search_cb = gnc_employee_search_select;
- else
- search_cb = gnc_employee_search_edit;
- type_name = GNC_EMPLOYEE_MODULE_NAME;
- break;
+ case GNC_OWNER_EMPLOYEE:
+ if (type == GNCSEARCH_TYPE_SELECT)
+ search_cb = gnc_employee_search_select;
+ else
+ search_cb = gnc_employee_search_edit;
+ type_name = GNC_EMPLOYEE_MODULE_NAME;
+ break;
- default:
- g_warning ("Unknown type");
- return NULL;
- }
+ default:
+ g_warning ("Unknown type");
+ return NULL;
+ }
- edit = gnc_general_search_new (type_name, text, text_editable, search_cb, book, book);
- if (!edit)
- return NULL;
+ edit = gnc_general_search_new (type_name, text, text_editable, search_cb, book, book);
+ if (!edit)
+ return NULL;
- gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit),
- owner->owner.undefined);
- gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
- if (label)
- gtk_label_set_text (GTK_LABEL (label), _(gncObjectGetTypeLabel (type_name)));
+ gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit),
+ owner->owner.undefined);
+ gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
+ if (label)
+ gtk_label_set_text (GTK_LABEL (label), _(gncObjectGetTypeLabel (type_name)));
- return edit;
+ return edit;
}
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
- QofBook *book, GncOwner *owner)
+ QofBook *book, GncOwner *owner)
{
- g_return_val_if_fail (hbox != NULL, NULL);
- g_return_val_if_fail (book != NULL, NULL);
- g_return_val_if_fail (owner != NULL, NULL);
+ g_return_val_if_fail (hbox != NULL, NULL);
+ g_return_val_if_fail (book != NULL, NULL);
+ g_return_val_if_fail (owner != NULL, NULL);
- return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_SELECT);
+ return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_SELECT);
}
GtkWidget * gnc_owner_edit_create (GtkWidget *label, GtkWidget *hbox,
- QofBook *book, GncOwner *owner)
+ QofBook *book, GncOwner *owner)
{
- g_return_val_if_fail (hbox != NULL, NULL);
- g_return_val_if_fail (book != NULL, NULL);
- g_return_val_if_fail (owner != NULL, NULL);
+ g_return_val_if_fail (hbox != NULL, NULL);
+ g_return_val_if_fail (book != NULL, NULL);
+ g_return_val_if_fail (owner != NULL, NULL);
- return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_EDIT);
+ return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_EDIT);
}
void gnc_owner_get_owner (GtkWidget *widget, GncOwner *owner)
{
- g_return_if_fail (widget != NULL);
- g_return_if_fail (owner != NULL);
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (owner != NULL);
- /* We'll assume that the owner has the proper 'type' because we
- * can't change it here. Hopefully the caller has it set properly
- */
- owner->owner.undefined =
- gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
+ /* We'll assume that the owner has the proper 'type' because we
+ * can't change it here. Hopefully the caller has it set properly
+ */
+ owner->owner.undefined =
+ gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
}
void gnc_owner_set_owner (GtkWidget *widget, GncOwner *owner)
{
- g_return_if_fail (widget != NULL);
- g_return_if_fail (owner != NULL);
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (owner != NULL);
- /* We'll assume that the owner has the proper 'type' because we
- * can't change it here. Hopefully the caller has it set properly
- */
+ /* We'll assume that the owner has the proper 'type' because we
+ * can't change it here. Hopefully the caller has it set properly
+ */
- gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget),
- owner->owner.undefined);
+ gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget),
+ owner->owner.undefined);
}
-typedef struct _invoice_select_info {
- GtkWidget *label;
- QofBook *book;
- GncOwner owner;
- gboolean have_owner;
+typedef struct _invoice_select_info
+{
+ GtkWidget *label;
+ QofBook *book;
+ GncOwner owner;
+ gboolean have_owner;
} GncISI;
static GNCSearchWindow *
gnc_invoice_select_search_cb (gpointer start, gpointer isip)
{
- GncISI *isi = isip;
+ GncISI *isi = isip;
- if (!isi) return NULL;
- g_assert(isi->book);
+ if (!isi) return NULL;
+ g_assert(isi->book);
- return gnc_invoice_search (start,
- isi->have_owner ? &isi->owner : NULL,
- isi->book);
+ return gnc_invoice_search (start,
+ isi->have_owner ? &isi->owner : NULL,
+ isi->book);
}
static void
gnc_invoice_select_search_set_label(GncISI* isi)
{
- GncOwnerType owner_type;
- GncOwner *tmp;
- char *label;
+ GncOwnerType owner_type;
+ GncOwner *tmp;
+ char *label;
- g_assert(isi);
- if (!isi->label) return;
+ g_assert(isi);
+ if (!isi->label) return;
- tmp = &isi->owner;
- owner_type = gncOwnerGetType(tmp);
- while (owner_type == GNC_OWNER_JOB) {
- tmp = gncOwnerGetEndOwner(tmp);
+ tmp = &isi->owner;
owner_type = gncOwnerGetType(tmp);
- }
+ while (owner_type == GNC_OWNER_JOB)
+ {
+ tmp = gncOwnerGetEndOwner(tmp);
+ owner_type = gncOwnerGetType(tmp);
+ }
- /* Translators: See comments in dialog-invoice.c:gnc_invoice_search() */
- switch (owner_type) {
- case GNC_OWNER_VENDOR:
- label = _("Bill");
- break;
- case GNC_OWNER_EMPLOYEE:
- label = _("Voucher");
- break;
- default:
- label = _("Invoice");
- }
+ /* Translators: See comments in dialog-invoice.c:gnc_invoice_search() */
+ switch (owner_type)
+ {
+ case GNC_OWNER_VENDOR:
+ label = _("Bill");
+ break;
+ case GNC_OWNER_EMPLOYEE:
+ label = _("Voucher");
+ break;
+ default:
+ label = _("Invoice");
+ }
- gtk_label_set_text(GTK_LABEL(isi->label), label);
+ gtk_label_set_text(GTK_LABEL(isi->label), label);
}
GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, QofBook *book,
- const GncOwner *owner,
- GncInvoice *invoice,
- GtkWidget *label)
+ const GncOwner *owner,
+ GncInvoice *invoice,
+ GtkWidget *label)
{
- GtkWidget *edit;
- GncISI *isi;
+ GtkWidget *edit;
+ GncISI *isi;
- g_return_val_if_fail (hbox != NULL, NULL);
- g_return_val_if_fail (book != NULL, NULL);
- /* Note: it is legal to have no owner or invoice */
+ g_return_val_if_fail (hbox != NULL, NULL);
+ g_return_val_if_fail (book != NULL, NULL);
+ /* Note: it is legal to have no owner or invoice */
- isi = g_new0(GncISI, 1);
- if (!isi)
- return NULL;
+ isi = g_new0(GncISI, 1);
+ if (!isi)
+ return NULL;
- if (owner) {
- gncOwnerCopy(owner, &isi->owner);
- isi->have_owner = TRUE;
- } else {
- gncOwnerInitCustomer(&isi->owner, NULL);
- }
- isi->book = book;
- isi->label = label;
+ if (owner)
+ {
+ gncOwnerCopy(owner, &isi->owner);
+ isi->have_owner = TRUE;
+ }
+ else
+ {
+ gncOwnerInitCustomer(&isi->owner, NULL);
+ }
+ isi->book = book;
+ isi->label = label;
- edit = gnc_general_search_new (GNC_INVOICE_MODULE_NAME, _("Select..."),
- TRUE, gnc_invoice_select_search_cb, isi, isi->book);
- if (!edit) {
- g_free(isi);
- return NULL;
- }
+ edit = gnc_general_search_new (GNC_INVOICE_MODULE_NAME, _("Select..."),
+ TRUE, gnc_invoice_select_search_cb, isi, isi->book);
+ if (!edit)
+ {
+ g_free(isi);
+ return NULL;
+ }
- gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), invoice);
- gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
- g_object_set_data_full(G_OBJECT(edit), "isi-state", isi, g_free);
+ gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), invoice);
+ gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
+ g_object_set_data_full(G_OBJECT(edit), "isi-state", isi, g_free);
- /* Set the label */
- gnc_invoice_select_search_set_label(isi);
+ /* Set the label */
+ gnc_invoice_select_search_set_label(isi);
- return edit;
+ return edit;
}
GncInvoice * gnc_invoice_get_invoice (GtkWidget *widget)
{
- g_return_val_if_fail (widget != NULL, NULL);
+ g_return_val_if_fail (widget != NULL, NULL);
- return gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
+ return gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
}
void gnc_invoice_set_invoice (GtkWidget *widget, GncInvoice *invoice)
{
- g_return_if_fail (widget != NULL);
- g_return_if_fail (invoice != NULL);
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (invoice != NULL);
- gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
+ gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
}
void gnc_invoice_set_owner (GtkWidget *widget, GncOwner *owner)
{
- GncISI *isi;
+ GncISI *isi;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (owner != NULL);
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (owner != NULL);
- isi = g_object_get_data(G_OBJECT(widget), "isi-state");
- g_assert(isi);
+ isi = g_object_get_data(G_OBJECT(widget), "isi-state");
+ g_assert(isi);
- if (isi->owner.owner.undefined == owner->owner.undefined)
- return;
+ if (isi->owner.owner.undefined == owner->owner.undefined)
+ return;
- gncOwnerCopy(owner, &isi->owner);
- isi->have_owner = TRUE;
- gnc_general_search_set_selected(GNC_GENERAL_SEARCH(widget), NULL);
+ gncOwnerCopy(owner, &isi->owner);
+ isi->have_owner = TRUE;
+ gnc_general_search_set_selected(GNC_GENERAL_SEARCH(widget), NULL);
- /* Reset the label */
- gnc_invoice_select_search_set_label(isi);
+ /* Reset the label */
+ gnc_invoice_select_search_set_label(isi);
}
void
gnc_fill_account_select_combo (GtkWidget *combo, QofBook *book,
- GList *acct_types, GList *acct_commodities)
+ GList *acct_types, GList *acct_commodities)
{
- GtkListStore *store;
- GtkEntry *entry;
- GList *list, *node;
- char *text;
+ GtkListStore *store;
+ GtkEntry *entry;
+ GList *list, *node;
+ char *text;
- g_return_if_fail (combo && GTK_IS_COMBO_BOX_ENTRY(combo));
- g_return_if_fail (book);
- g_return_if_fail (acct_types);
+ g_return_if_fail (combo && GTK_IS_COMBO_BOX_ENTRY(combo));
+ g_return_if_fail (book);
+ g_return_if_fail (acct_types);
- /* Figure out if anything is set in the combo */
- text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
+ /* Figure out if anything is set in the combo */
+ text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
- list = gnc_account_get_descendants (gnc_book_get_root_account (book));
+ list = gnc_account_get_descendants (gnc_book_get_root_account (book));
- /* Clear the existing list */
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
- gtk_entry_set_text(entry, "");
- store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
- gtk_list_store_clear(store);
+ /* Clear the existing list */
+ entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
+ gtk_entry_set_text(entry, "");
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
+ gtk_list_store_clear(store);
- /* Add the account names to the combo box */
- for (node = list; node; node = node->next) {
- Account *account = node->data;
- char *name;
+ /* Add the account names to the combo box */
+ for (node = list; node; node = node->next)
+ {
+ Account *account = node->data;
+ char *name;
- /* Only present accounts of the appropriate type */
- if (g_list_index (acct_types, (gpointer)xaccAccountGetType (account))
- == -1)
- continue;
+ /* Only present accounts of the appropriate type */
+ if (g_list_index (acct_types, (gpointer)xaccAccountGetType (account))
+ == -1)
+ continue;
- /* Only present accounts with the right commodity, if that's a
- restriction */
- if (acct_commodities)
- {
- if ( g_list_find_custom( acct_commodities,
- GINT_TO_POINTER(xaccAccountGetCommodity(account)),
- gnc_commodity_compare_void) == NULL ) {
- continue;
+ /* Only present accounts with the right commodity, if that's a
+ restriction */
+ if (acct_commodities)
+ {
+ if ( g_list_find_custom( acct_commodities,
+ GINT_TO_POINTER(xaccAccountGetCommodity(account)),
+ gnc_commodity_compare_void) == NULL )
+ {
+ continue;
+ }
}
+
+ name = gnc_account_get_full_name (account);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo), name);
+ g_free(name);
}
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
- name = gnc_account_get_full_name (account);
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo), name);
- g_free(name);
- }
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+ g_list_free (list);
- g_list_free (list);
+ gnc_cbe_set_by_string(GTK_COMBO_BOX_ENTRY(combo), text);
- gnc_cbe_set_by_string(GTK_COMBO_BOX_ENTRY(combo), text);
-
- if (text)
- g_free (text);
+ if (text)
+ g_free (text);
}
GList *
gnc_business_account_types (GncOwner *owner)
{
- g_return_val_if_fail (owner, NULL);
+ g_return_val_if_fail (owner, NULL);
- switch (gncOwnerGetType (owner)) {
- case GNC_OWNER_CUSTOMER:
- return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_RECEIVABLE));
- case GNC_OWNER_VENDOR:
- case GNC_OWNER_EMPLOYEE:
- return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_PAYABLE));
- break;
- default:
- return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_NONE));
- }
+ switch (gncOwnerGetType (owner))
+ {
+ case GNC_OWNER_CUSTOMER:
+ return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_RECEIVABLE));
+ case GNC_OWNER_VENDOR:
+ case GNC_OWNER_EMPLOYEE:
+ return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_PAYABLE));
+ break;
+ default:
+ return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_NONE));
+ }
}
GList *
gnc_business_commodities (GncOwner *owner)
{
- g_return_val_if_fail (owner, NULL);
- g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);
+ g_return_val_if_fail (owner, NULL);
+ g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);
- return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
+ return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
}
/*********************************************************************/
@@ -396,20 +409,21 @@
typedef const char * (*GenericLookup_t)(gpointer);
-typedef struct {
- gint component_id;
- GtkWidget * omenu;
- QofBook * book;
- gboolean none_ok;
- const char * (*get_name)(gpointer);
- GList * (*get_list)(QofBook*);
+typedef struct
+{
+ gint component_id;
+ GtkWidget * omenu;
+ QofBook * book;
+ gboolean none_ok;
+ const char * (*get_name)(gpointer);
+ GList * (*get_list)(QofBook*);
- gboolean building_menu;
- gpointer result;
- gpointer * result_p;
+ gboolean building_menu;
+ gpointer result;
+ gpointer * result_p;
- void (*changed_cb)(GtkWidget*, gpointer);
- gpointer cb_arg;
+ void (*changed_cb)(GtkWidget*, gpointer);
+ gpointer cb_arg;
} OpMenuData;
#define DO_ADD_ITEM(s,o) { \
@@ -421,188 +435,191 @@
static void
business_option_changed (GtkWidget *widget, gpointer data)
{
- OpMenuData *omd = data;
+ OpMenuData *omd = data;
- g_return_if_fail (omd);
- omd->result = g_object_get_data (G_OBJECT (widget), "this_item");
+ g_return_if_fail (omd);
+ omd->result = g_object_get_data (G_OBJECT (widget), "this_item");
- if (!omd->building_menu) {
- if (omd->result_p)
- *(omd->result_p) = omd->result;
+ if (!omd->building_menu)
+ {
+ if (omd->result_p)
+ *(omd->result_p) = omd->result;
- if (omd->changed_cb)
- (omd->changed_cb)(omd->omenu, omd->cb_arg);
- }
+ if (omd->changed_cb)
+ (omd->changed_cb)(omd->omenu, omd->cb_arg);
+ }
}
static void
add_menu_item (GtkWidget *menu, const char *label, OpMenuData *omd,
- gpointer this_item)
+ gpointer this_item)
{
- GtkWidget *item = gtk_menu_item_new_with_label (label);
- g_object_set_data (G_OBJECT (item), "this_item", this_item);
- g_signal_connect (G_OBJECT (item), "activate",
- G_CALLBACK (business_option_changed), omd);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
+ GtkWidget *item = gtk_menu_item_new_with_label (label);
+ g_object_set_data (G_OBJECT (item), "this_item", this_item);
+ g_signal_connect (G_OBJECT (item), "activate",
+ G_CALLBACK (business_option_changed), omd);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
}
static void
generic_omenu_destroy_cb (GtkWidget *widget, gpointer data)
{
- OpMenuData *omd = data;
+ OpMenuData *omd = data;
- gnc_unregister_gui_component (omd->component_id);
- g_free (omd);
+ gnc_unregister_gui_component (omd->component_id);
+ g_free (omd);
}
static void
build_generic_optionmenu (OpMenuData *omd)
{
- GList *items;
- GtkWidget *menu;
- int current = 0, index = 0;
+ GList *items;
+ GtkWidget *menu;
+ int current = 0, index = 0;
- /* Make sure we can "get_list" */
- if (omd->get_list == NULL)
- return;
+ /* Make sure we can "get_list" */
+ if (omd->get_list == NULL)
+ return;
- /* Get the list of items */
- items = (omd->get_list)(omd->book);
+ /* Get the list of items */
+ items = (omd->get_list)(omd->book);
- /* Make a menu */
- menu = gtk_menu_new ();
+ /* Make a menu */
+ menu = gtk_menu_new ();
- omd->building_menu = TRUE;
+ omd->building_menu = TRUE;
- if (omd->none_ok || items == NULL)
- DO_ADD_ITEM (_("None"), NULL);
+ if (omd->none_ok || items == NULL)
+ DO_ADD_ITEM (_("None"), NULL);
- for ( ; items; items = items->next)
- DO_ADD_ITEM ((omd->get_name)(items->data), items->data);
+ for ( ; items; items = items->next)
+ DO_ADD_ITEM ((omd->get_name)(items->data), items->data);
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omd->omenu), menu);
- gtk_option_menu_set_history (GTK_OPTION_MENU (omd->omenu), current);
- gtk_widget_show (menu);
+ gtk_option_menu_set_menu (GTK_OPTION_MENU (omd->omenu), menu);
+ gtk_option_menu_set_history (GTK_OPTION_MENU (omd->omenu), current);
+ gtk_widget_show (menu);
- omd->building_menu = FALSE;
+ omd->building_menu = FALSE;
}
static void
generic_omenu_refresh_handler (GHashTable *changes, gpointer user_data)
{
- OpMenuData *omd = user_data;
- build_generic_optionmenu (omd);
+ OpMenuData *omd = user_data;
+ build_generic_optionmenu (omd);
}
static OpMenuData *
make_generic_optionmenu (GtkWidget *omenu, QofBook *book,
- gboolean none_ok, GNCIdType type_name,
- GList * (*get_list)(QofBook*),
- GenericLookup_t get_name,
- gpointer *result)
+ gboolean none_ok, GNCIdType type_name,
+ GList * (*get_list)(QofBook*),
+ GenericLookup_t get_name,
+ gpointer *result)
{
- OpMenuData *omd;
+ OpMenuData *omd;
- omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
+ omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
- /* If this is the first time we've been called, then build the
- * Option Menu Data object, register with the component manager, and
- * watch for changed items. Then register for deletion, so we can
- * unregister and free the data when this menu is destroyed.
- */
- if (!omd) {
- omd = g_new0 (OpMenuData, 1);
- omd->omenu = omenu;
- omd->book = book;
- omd->result_p = result;
- omd->none_ok = none_ok;
- omd->get_name = get_name;
- omd->get_list = get_list;
- g_object_set_data (G_OBJECT (omenu), "menu-data", omd);
+ /* If this is the first time we've been called, then build the
+ * Option Menu Data object, register with the component manager, and
+ * watch for changed items. Then register for deletion, so we can
+ * unregister and free the data when this menu is destroyed.
+ */
+ if (!omd)
+ {
+ omd = g_new0 (OpMenuData, 1);
+ omd->omenu = omenu;
+ omd->book = book;
+ omd->result_p = result;
+ omd->none_ok = none_ok;
+ omd->get_name = get_name;
+ omd->get_list = get_list;
+ g_object_set_data (G_OBJECT (omenu), "menu-data", omd);
- if (result)
- omd->result = *result;
+ if (result)
+ omd->result = *result;
- omd->component_id =
- gnc_register_gui_component ("generic-omenu-refresh-hook",
- generic_omenu_refresh_handler,
- NULL, omd);
+ omd->component_id =
+ gnc_register_gui_component ("generic-omenu-refresh-hook",
+ generic_omenu_refresh_handler,
+ NULL, omd);
- if (type_name)
- gnc_gui_component_watch_entity_type (omd->component_id,
- type_name,
- QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
+ if (type_name)
+ gnc_gui_component_watch_entity_type (omd->component_id,
+ type_name,
+ QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
- g_signal_connect (G_OBJECT (omenu), "destroy",
- G_CALLBACK (generic_omenu_destroy_cb), omd);
+ g_signal_connect (G_OBJECT (omenu), "destroy",
+ G_CALLBACK (generic_omenu_destroy_cb), omd);
- }
+ }
- build_generic_optionmenu (omd);
+ build_generic_optionmenu (omd);
- return omd;
+ return omd;
}
void
gnc_ui_optionmenu_set_changed_callback (GtkWidget *omenu,
- void (*changed_cb)(GtkWidget*,gpointer),
- gpointer cb_arg)
+ void (*changed_cb)(GtkWidget*, gpointer),
+ gpointer cb_arg)
{
- OpMenuData *omd;
+ OpMenuData *omd;
- if (!omenu) return;
+ if (!omenu) return;
- omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
- g_return_if_fail (omd);
+ omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
+ g_return_if_fail (omd);
- omd->changed_cb = changed_cb;
- omd->cb_arg = cb_arg;
+ omd->changed_cb = changed_cb;
+ omd->cb_arg = cb_arg;
}
gpointer
gnc_ui_optionmenu_get_value (GtkWidget *omenu)
{
- OpMenuData *omd;
+ OpMenuData *omd;
- if (!omenu) return NULL;
+ if (!omenu) return NULL;
- omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
- g_return_val_if_fail (omd, NULL);
+ omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
+ g_return_val_if_fail (omd, NULL);
- return omd->result;
+ return omd->result;
}
void
gnc_ui_optionmenu_set_value (GtkWidget *omenu, gpointer data)
{
- OpMenuData *omd;
- GtkWidget *menu;
- GList *node;
- gint counter;
+ OpMenuData *omd;
+ GtkWidget *menu;
+ GList *node;
+ gint counter;
- if (!omenu) return;
+ if (!omenu) return;
- omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
- g_return_if_fail (omd);
+ omd = g_object_get_data (G_OBJECT (omenu), "menu-data");
+ g_return_if_fail (omd);
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu));
- g_return_if_fail (menu);
+ menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu));
+ g_return_if_fail (menu);
- /* now walk all the children until we find our object */
- for (counter = 0, node = ((GTK_MENU_SHELL (menu))->children);
- node;
- node = node->next, counter++)
- {
- GObject *menuitem = node->data;
- gpointer this_object = g_object_get_data (menuitem, "this_item");
+ /* now walk all the children until we find our object */
+ for (counter = 0, node = ((GTK_MENU_SHELL (menu))->children);
+ node;
+ node = node->next, counter++)
+ {
+ GObject *menuitem = node->data;
+ gpointer this_object = g_object_get_data (menuitem, "this_item");
- if (this_object == data) {
- gtk_option_menu_set_history (GTK_OPTION_MENU (omd->omenu), counter);
- return;
+ if (this_object == data)
+ {
+ gtk_option_menu_set_history (GTK_OPTION_MENU (omd->omenu), counter);
+ return;
+ }
}
- }
}
/* Create an optionmenu of available billing terms and attach it to
@@ -614,60 +631,60 @@
*/
void
gnc_ui_billterms_optionmenu (GtkWidget *omenu, QofBook *book,
- gboolean none_ok, GncBillTerm **choice)
+ gboolean none_ok, GncBillTerm **choice)
{
- if (!omenu || !book) return;
+ if (!omenu || !book) return;
- make_generic_optionmenu (omenu, book, none_ok, GNC_BILLTERM_MODULE_NAME,
- gncBillTermGetTerms,
- (GenericLookup_t)gncBillTermGetName,
- (gpointer *)choice);
+ make_generic_optionmenu (omenu, book, none_ok, GNC_BILLTERM_MODULE_NAME,
+ gncBillTermGetTerms,
+ (GenericLookup_t)gncBillTermGetName,
+ (gpointer *)choice);
}
void
gnc_ui_taxtables_optionmenu (GtkWidget *omenu, QofBook *book,
- gboolean none_ok, GncTaxTable **choice)
+ gboolean none_ok, GncTaxTable **choice)
{
- if (!omenu || !book) return;
+ if (!omenu || !book) return;
- make_generic_optionmenu (omenu, book, none_ok, GNC_TAXTABLE_MODULE_NAME,
- gncTaxTableGetTables,
- (GenericLookup_t)gncTaxTableGetName,
- (gpointer *)choice);
+ make_generic_optionmenu (omenu, book, none_ok, GNC_TAXTABLE_MODULE_NAME,
+ gncTaxTableGetTables,
+ (GenericLookup_t)gncTaxTableGetName,
+ (gpointer *)choice);
}
void
gnc_ui_taxincluded_optionmenu (GtkWidget *omenu, GncTaxIncluded *choice)
{
- GtkWidget *menu;
- OpMenuData *omd;
- int current = 0, index = 0;
+ GtkWidget *menu;
+ OpMenuData *omd;
+ int current = 0, index = 0;
- if (!omenu) return;
+ if (!omenu) return;
- omd = make_generic_optionmenu (omenu, NULL, FALSE, NULL, NULL, NULL,
- (gpointer *)choice);
+ omd = make_generic_optionmenu (omenu, NULL, FALSE, NULL, NULL, NULL,
+ (gpointer *)choice);
- g_return_if_fail (omd);
+ g_return_if_fail (omd);
- menu = gtk_menu_new ();
+ menu = gtk_menu_new ();
- add_menu_item (menu, _("Yes"), omd,
- GINT_TO_POINTER (GNC_TAXINCLUDED_YES));
- if (*choice == GNC_TAXINCLUDED_YES) current = index;
- index++;
+ add_menu_item (menu, _("Yes"), omd,
+ GINT_TO_POINTER (GNC_TAXINCLUDED_YES));
+ if (*choice == GNC_TAXINCLUDED_YES) current = index;
+ index++;
- add_menu_item (menu, _("No"), omd,
- GINT_TO_POINTER (GNC_TAXINCLUDED_NO));
- if (*choice == GNC_TAXINCLUDED_NO) current = index;
- index++;
+ add_menu_item (menu, _("No"), omd,
+ GINT_TO_POINTER (GNC_TAXINCLUDED_NO));
+ if (*choice == GNC_TAXINCLUDED_NO) current = index;
+ index++;
- add_menu_item (menu, _("Use Global"), omd,
- GINT_TO_POINTER (GNC_TAXINCLUDED_USEGLOBAL));
- if (*choice == GNC_TAXINCLUDED_USEGLOBAL) current = index;
- index++;
+ add_menu_item (menu, _("Use Global"), omd,
+ GINT_TO_POINTER (GNC_TAXINCLUDED_USEGLOBAL));
+ if (*choice == GNC_TAXINCLUDED_USEGLOBAL) current = index;
+ index++;
- gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
- gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current);
- gtk_widget_show (menu);
+ gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
+ gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), current);
+ gtk_widget_show (menu);
}
Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -38,22 +38,22 @@
#define GCONF_SECTION_EMPLOYEE "dialogs/business/employee"
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
- QofBook *book, GncOwner *owner);
+ QofBook *book, GncOwner *owner);
GtkWidget * gnc_owner_edit_create (GtkWidget *label, GtkWidget *hbox,
- QofBook *book, GncOwner *owner);
+ QofBook *book, GncOwner *owner);
void gnc_owner_get_owner (GtkWidget *widget, GncOwner *owner);
void gnc_owner_set_owner (GtkWidget *widget, GncOwner *owner);
-/* An invoice select widget..
+/* An invoice select widget..
* the owner, invoice, and label parameters are optional
*/
GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, QofBook *book,
- const GncOwner *owner,
- GncInvoice *invoice,
- GtkWidget *label);
+ const GncOwner *owner,
+ GncInvoice *invoice,
+ GtkWidget *label);
GncInvoice * gnc_invoice_get_invoice (GtkWidget *widget);
void gnc_invoice_set_invoice (GtkWidget *widget, GncInvoice *invoice);
@@ -67,8 +67,8 @@
/* Fill in a combo box with the appropriate list of accounts */
void gnc_fill_account_select_combo (GtkWidget *combo, QofBook *book,
- GList *acct_types,
- GList *acct_commodities);
+ GList *acct_types,
+ GList *acct_commodities);
/* Create an optionmenu of available billing terms and attach it to
@@ -79,12 +79,12 @@
* created.
*/
void gnc_ui_billterms_optionmenu (GtkWidget *omenu, QofBook *book,
- gboolean none_ok, GncBillTerm **choice);
+ gboolean none_ok, GncBillTerm **choice);
/* Same thing except for the tax tables */
void
gnc_ui_taxtables_optionmenu (GtkWidget *omenu, QofBook *book,
- gboolean none_ok, GncTaxTable **choice);
+ gboolean none_ok, GncTaxTable **choice);
/* Build an option menu for choosing a GncTaxIncluded */
void gnc_ui_taxincluded_optionmenu (GtkWidget *omenu, GncTaxIncluded *choice);
@@ -97,8 +97,8 @@
*/
void gnc_ui_optionmenu_set_changed_callback (GtkWidget *omenu,
- void (*changed_cb)(GtkWidget*,gpointer),
- gpointer cb_arg);
+ void (*changed_cb)(GtkWidget*, gpointer),
+ gpointer cb_arg);
gpointer gnc_ui_optionmenu_get_value (GtkWidget *omenu);
void gnc_ui_optionmenu_set_value (GtkWidget *omenu, gpointer data);
Modified: gnucash/trunk/src/business/business-gnome/business-options-gnome.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-options-gnome.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/business-options-gnome.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -44,48 +44,49 @@
static GtkWidget *
create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox)
{
- GtkWidget *widget;
- GncOwner owner;
+ GtkWidget *widget;
+ GncOwner owner;
- switch (type) {
- case GNC_OWNER_CUSTOMER:
- gncOwnerInitCustomer (&owner, NULL);
- break;
- case GNC_OWNER_VENDOR:
- gncOwnerInitVendor (&owner, NULL);
- break;
- case GNC_OWNER_EMPLOYEE:
- gncOwnerInitEmployee (&owner, NULL);
- break;
- case GNC_OWNER_JOB:
- gncOwnerInitJob (&owner, NULL);
- break;
- default:
- return NULL;
- }
+ switch (type)
+ {
+ case GNC_OWNER_CUSTOMER:
+ gncOwnerInitCustomer (&owner, NULL);
+ break;
+ case GNC_OWNER_VENDOR:
+ gncOwnerInitVendor (&owner, NULL);
+ break;
+ case GNC_OWNER_EMPLOYEE:
+ gncOwnerInitEmployee (&owner, NULL);
+ break;
+ case GNC_OWNER_JOB:
+ gncOwnerInitJob (&owner, NULL);
+ break;
+ default:
+ return NULL;
+ }
- widget = gnc_owner_select_create (NULL, hbox,
- gnc_get_current_book (), &owner);
- gnc_option_set_widget (option, widget);
+ widget = gnc_owner_select_create (NULL, hbox,
+ gnc_get_current_book (), &owner);
+ gnc_option_set_widget (option, widget);
- g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (gnc_option_changed_option_cb), option);
+ g_signal_connect (G_OBJECT (widget), "changed",
+ G_CALLBACK (gnc_option_changed_option_cb), option);
- return widget;
+ return widget;
}
static GtkWidget *
make_name_label (char *name)
{
- GtkWidget *label;
- gchar *colon_name;
+ GtkWidget *label;
+ gchar *colon_name;
- colon_name = g_strconcat (name, ":", (char *)NULL);
- label = gtk_label_new (colon_name);
- gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
- g_free (colon_name);
+ colon_name = g_strconcat (name, ":", (char *)NULL);
+ label = gtk_label_new (colon_name);
+ gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+ g_free (colon_name);
- return label;
+ return label;
}
/********************************************************************/
@@ -95,75 +96,76 @@
static GncOwnerType
get_owner_type_from_option (GNCOption *option)
{
- SCM odata = gnc_option_get_option_data (option);
+ SCM odata = gnc_option_get_option_data (option);
- /* The option data is enum-typed. It's just the enum value. */
- return (GncOwnerType) scm_num2int(odata, SCM_ARG1, G_STRFUNC);
+ /* The option data is enum-typed. It's just the enum value. */
+ return (GncOwnerType) scm_num2int(odata, SCM_ARG1, G_STRFUNC);
}
/* Function to set the UI widget based upon the option */
static GtkWidget *
owner_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_owner_widget (option, get_owner_type_from_option (option),
- *enclosing);
+ value = create_owner_widget (option, get_owner_type_from_option (option),
+ *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
owner_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncOwner owner_def;
- GncOwner *owner;
+ GncOwner owner_def;
+ GncOwner *owner;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:owner_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:owner_set_value",
+ "SCM is not a wrapped pointer.", value);
- owner = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncOwner"), 1, 0);
+ owner = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncOwner"), 1, 0);
- /* XXX: should we verify that the owner type is correct? */
- if (!owner) {
- owner_def.type = get_owner_type_from_option (option);
- owner_def.owner.undefined = NULL;
- owner = &owner_def;
- }
+ /* XXX: should we verify that the owner type is correct? */
+ if (!owner)
+ {
+ owner_def.type = get_owner_type_from_option (option);
+ owner_def.owner.undefined = NULL;
+ owner = &owner_def;
+ }
- widget = gnc_option_get_widget (option);
- gnc_owner_set_owner (widget, owner);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_owner_set_owner (widget, owner);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
owner_get_value (GNCOption *option, GtkWidget *widget)
{
- static GncOwner owner; /* XXX: might cause trouble? */
- GncOwnerType type;
+ static GncOwner owner; /* XXX: might cause trouble? */
+ GncOwnerType type;
- type = get_owner_type_from_option (option);
- owner.type = type;
- gnc_owner_get_owner (widget, &owner);
+ type = get_owner_type_from_option (option);
+ owner.type = type;
+ gnc_owner_get_owner (widget, &owner);
- return SWIG_NewPointerObj(&owner, SWIG_TypeQuery("_p__gncOwner"), 0);
+ return SWIG_NewPointerObj(&owner, SWIG_TypeQuery("_p__gncOwner"), 0);
}
@@ -174,55 +176,55 @@
/* Function to set the UI widget based upon the option */
static GtkWidget *
customer_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_owner_widget (option, GNC_OWNER_CUSTOMER, *enclosing);
+ value = create_owner_widget (option, GNC_OWNER_CUSTOMER, *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
customer_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncOwner owner;
- GncCustomer *customer;
+ GncOwner owner;
+ GncCustomer *customer;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:customer_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:customer_set_value",
+ "SCM is not a wrapped pointer.", value);
- customer = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0);
- gncOwnerInitCustomer (&owner, customer);
+ customer = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0);
+ gncOwnerInitCustomer (&owner, customer);
- widget = gnc_option_get_widget (option);
- gnc_owner_set_owner (widget, &owner);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_owner_set_owner (widget, &owner);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
customer_get_value (GNCOption *option, GtkWidget *widget)
{
- GncOwner owner;
+ GncOwner owner;
- gnc_owner_get_owner (widget, &owner);
- return SWIG_NewPointerObj(owner.owner.undefined,
- SWIG_TypeQuery("_p__gncCustomer"), 0);
+ gnc_owner_get_owner (widget, &owner);
+ return SWIG_NewPointerObj(owner.owner.undefined,
+ SWIG_TypeQuery("_p__gncCustomer"), 0);
}
@@ -233,55 +235,55 @@
/* Function to set the UI widget based upon the option */
static GtkWidget *
vendor_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_owner_widget (option, GNC_OWNER_VENDOR, *enclosing);
+ value = create_owner_widget (option, GNC_OWNER_VENDOR, *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
vendor_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncOwner owner;
- GncVendor *vendor;
+ GncOwner owner;
+ GncVendor *vendor;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:vendor_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:vendor_set_value",
+ "SCM is not a wrapped pointer.", value);
- vendor = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0);
- gncOwnerInitVendor (&owner, vendor);
+ vendor = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0);
+ gncOwnerInitVendor (&owner, vendor);
- widget = gnc_option_get_widget (option);
- gnc_owner_set_owner (widget, &owner);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_owner_set_owner (widget, &owner);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
vendor_get_value (GNCOption *option, GtkWidget *widget)
{
- GncOwner owner;
+ GncOwner owner;
- gnc_owner_get_owner (widget, &owner);
- return SWIG_NewPointerObj(owner.owner.undefined,
- SWIG_TypeQuery("_p__gncVendor"), 0);
+ gnc_owner_get_owner (widget, &owner);
+ return SWIG_NewPointerObj(owner.owner.undefined,
+ SWIG_TypeQuery("_p__gncVendor"), 0);
}
/********************************************************************/
@@ -291,56 +293,56 @@
/* Function to set the UI widget based upon the option */
static GtkWidget *
employee_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_owner_widget (option, GNC_OWNER_EMPLOYEE, *enclosing);
+ value = create_owner_widget (option, GNC_OWNER_EMPLOYEE, *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
employee_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncOwner owner;
- GncEmployee *employee;
+ GncOwner owner;
+ GncEmployee *employee;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:employee_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:employee_set_value",
+ "SCM is not a wrapped pointer.", value);
- employee = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncEmployee"), 1, 0);
- gncOwnerInitEmployee (&owner, employee);
+ employee = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncEmployee"), 1, 0);
+ gncOwnerInitEmployee (&owner, employee);
- widget = gnc_option_get_widget (option);
- gnc_owner_set_owner (widget, &owner);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_owner_set_owner (widget, &owner);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
employee_get_value (GNCOption *option, GtkWidget *widget)
{
- GncOwner owner;
+ GncOwner owner;
- gnc_owner_get_owner (widget, &owner);
+ gnc_owner_get_owner (widget, &owner);
- return SWIG_NewPointerObj(owner.owner.undefined,
- SWIG_TypeQuery("_p__gncEmployee"), 0);
+ return SWIG_NewPointerObj(owner.owner.undefined,
+ SWIG_TypeQuery("_p__gncEmployee"), 0);
}
/********************************************************************/
@@ -350,68 +352,68 @@
static GtkWidget *
create_invoice_widget (GNCOption *option, GtkWidget *hbox)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- /* No owner or starting invoice here, but that's okay. */
- widget = gnc_invoice_select_create (hbox, gnc_get_current_book(),
- NULL, NULL, NULL);
+ /* No owner or starting invoice here, but that's okay. */
+ widget = gnc_invoice_select_create (hbox, gnc_get_current_book(),
+ NULL, NULL, NULL);
- gnc_option_set_widget (option, widget);
- g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (gnc_option_changed_option_cb), option);
+ gnc_option_set_widget (option, widget);
+ g_signal_connect (G_OBJECT (widget), "changed",
+ G_CALLBACK (gnc_option_changed_option_cb), option);
- return widget;
+ return widget;
}
/* Function to set the UI widget based upon the option */
static GtkWidget *
invoice_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_invoice_widget (option, *enclosing);
+ value = create_invoice_widget (option, *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
invoice_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncInvoice *invoice;
+ GncInvoice *invoice;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:invoice_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:invoice_set_value",
+ "SCM is not a wrapped pointer.", value);
- invoice = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0);
+ invoice = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0);
- widget = gnc_option_get_widget (option);
- gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
invoice_get_value (GNCOption *option, GtkWidget *widget)
{
- GncInvoice *invoice;
+ GncInvoice *invoice;
- invoice = gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
- return SWIG_NewPointerObj(invoice, SWIG_TypeQuery("_p__gncInvoice"), 0);
+ invoice = gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
+ return SWIG_NewPointerObj(invoice, SWIG_TypeQuery("_p__gncInvoice"), 0);
}
@@ -422,71 +424,71 @@
static GtkWidget *
create_taxtable_widget (GNCOption *option, GtkWidget *hbox)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- widget = gtk_option_menu_new ();
+ widget = gtk_option_menu_new ();
- gnc_ui_taxtables_optionmenu (widget, gnc_get_current_book (), TRUE, NULL);
-
- gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
- gnc_option_set_widget (option, widget);
+ gnc_ui_taxtables_optionmenu (widget, gnc_get_current_book (), TRUE, NULL);
- gnc_ui_optionmenu_set_changed_callback (widget,
- (void(*)(GtkWidget*,gpointer))gnc_option_changed_option_cb,
- option);
+ gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+ gnc_option_set_widget (option, widget);
- return widget;
+ gnc_ui_optionmenu_set_changed_callback (widget,
+ (void(*)(GtkWidget*, gpointer))gnc_option_changed_option_cb,
+ option);
+
+ return widget;
}
/* Function to set the UI widget based upon the option */
static GtkWidget *
taxtable_set_widget (GNCOption *option, GtkBox *page_box,
- GtkTooltips *tooltips,
- char *name, char *documentation,
- /* Return values */
- GtkWidget **enclosing, gboolean *packed)
+ GtkTooltips *tooltips,
+ char *name, char *documentation,
+ /* Return values */
+ GtkWidget **enclosing, gboolean *packed)
{
- GtkWidget *value;
- GtkWidget *label;
+ GtkWidget *value;
+ GtkWidget *label;
- *enclosing = gtk_hbox_new (FALSE, 5);
- label = make_name_label (name);
- gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
+ *enclosing = gtk_hbox_new (FALSE, 5);
+ label = make_name_label (name);
+ gtk_box_pack_start (GTK_BOX (*enclosing), label, FALSE, FALSE, 0);
- value = create_taxtable_widget (option, *enclosing);
+ value = create_taxtable_widget (option, *enclosing);
- gnc_option_set_ui_value (option, FALSE);
+ gnc_option_set_ui_value (option, FALSE);
- gtk_widget_show_all (*enclosing);
- return value;
+ gtk_widget_show_all (*enclosing);
+ return value;
}
/* Function to set the UI Value for a particular option */
static gboolean
taxtable_set_value (GNCOption *option, gboolean use_default,
- GtkWidget *widget, SCM value)
+ GtkWidget *widget, SCM value)
{
- GncTaxTable *taxtable;
+ GncTaxTable *taxtable;
- if (!SWIG_IsPointer (value))
- scm_misc_error("business_options:taxtable_set_value",
- "SCM is not a wrapped pointer.", value);
+ if (!SWIG_IsPointer (value))
+ scm_misc_error("business_options:taxtable_set_value",
+ "SCM is not a wrapped pointer.", value);
- taxtable = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0);
+ taxtable = SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0);
- widget = gnc_option_get_widget (option);
- gnc_ui_optionmenu_set_value (widget, taxtable);
- return FALSE;
+ widget = gnc_option_get_widget (option);
+ gnc_ui_optionmenu_set_value (widget, taxtable);
+ return FALSE;
}
/* Function to get the UI Value for a particular option */
static SCM
taxtable_get_value (GNCOption *option, GtkWidget *widget)
{
- GncTaxTable *taxtable;
+ GncTaxTable *taxtable;
- taxtable = gnc_ui_optionmenu_get_value (widget);
- return SWIG_NewPointerObj(taxtable, SWIG_TypeQuery("_p__gncTaxTable"), 0);
+ taxtable = gnc_ui_optionmenu_get_value (widget);
+ return SWIG_NewPointerObj(taxtable, SWIG_TypeQuery("_p__gncTaxTable"), 0);
}
@@ -495,19 +497,22 @@
void
gnc_business_options_gnome_initialize (void)
{
- int i;
- static GNCOptionDef_t options[] = {
- { "owner", owner_set_widget, owner_set_value, owner_get_value },
- { "customer", customer_set_widget, customer_set_value,
- customer_get_value },
- { "vendor", vendor_set_widget, vendor_set_value, vendor_get_value },
- { "employee", employee_set_widget, employee_set_value, employee_get_value },
- { "invoice", invoice_set_widget, invoice_set_value, invoice_get_value },
- { "taxtable", taxtable_set_widget, taxtable_set_value, taxtable_get_value },
- { NULL }
- };
+ int i;
+ static GNCOptionDef_t options[] =
+ {
+ { "owner", owner_set_widget, owner_set_value, owner_get_value },
+ {
+ "customer", customer_set_widget, customer_set_value,
+ customer_get_value
+ },
+ { "vendor", vendor_set_widget, vendor_set_value, vendor_get_value },
+ { "employee", employee_set_widget, employee_set_value, employee_get_value },
+ { "invoice", invoice_set_widget, invoice_set_value, invoice_get_value },
+ { "taxtable", taxtable_set_widget, taxtable_set_value, taxtable_get_value },
+ { NULL }
+ };
- SWIG_GetModule(NULL); /* Work-around for SWIG bug. */
- for (i = 0; options[i].option_name; i++)
- gnc_options_ui_register_option (&(options[i]));
+ SWIG_GetModule(NULL); /* Work-around for SWIG bug. */
+ for (i = 0; options[i].option_name; i++)
+ gnc_options_ui_register_option (&(options[i]));
}
Modified: gnucash/trunk/src/business/business-gnome/business-urls.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-urls.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/business-urls.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -87,78 +87,78 @@
static gboolean
customerCB (const char *location, const char *label,
- gboolean new_window, GNCURLResult * result)
+ gboolean new_window, GNCURLResult * result)
{
- QofInstance *entity;
- GncCustomer *customer;
+ QofInstance *entity;
+ GncCustomer *customer;
- /* href="...:customer=<guid>" */
- HANDLE_TYPE ("customer=", GNC_ID_CUSTOMER);
- customer = (GncCustomer *) entity;
- gnc_ui_customer_edit (customer);
+ /* href="...:customer=<guid>" */
+ HANDLE_TYPE ("customer=", GNC_ID_CUSTOMER);
+ customer = (GncCustomer *) entity;
+ gnc_ui_customer_edit (customer);
- return TRUE;
+ return TRUE;
}
static gboolean
vendorCB (const char *location, const char *label,
- gboolean new_window, GNCURLResult * result)
+ gboolean new_window, GNCURLResult * result)
{
- QofInstance *entity;
- GncVendor *vendor;
+ QofInstance *entity;
+ GncVendor *vendor;
- /* href="...:vendor=<guid>" */
- HANDLE_TYPE ("vendor=", GNC_ID_VENDOR);
- vendor = (GncVendor *) entity;
- gnc_ui_vendor_edit (vendor);
+ /* href="...:vendor=<guid>" */
+ HANDLE_TYPE ("vendor=", GNC_ID_VENDOR);
+ vendor = (GncVendor *) entity;
+ gnc_ui_vendor_edit (vendor);
- return TRUE;
+ return TRUE;
}
static gboolean
employeeCB (const char *location, const char *label,
- gboolean new_window, GNCURLResult * result)
+ gboolean new_window, GNCURLResult * result)
{
- QofInstance *entity;
- GncEmployee *employee;
+ QofInstance *entity;
+ GncEmployee *employee;
- /* href="...:employee=<guid>" */
- HANDLE_TYPE ("employee=", GNC_ID_EMPLOYEE);
+ /* href="...:employee=<guid>" */
+ HANDLE_TYPE ("employee=", GNC_ID_EMPLOYEE);
- employee = (GncEmployee *) entity;
- gnc_ui_employee_edit (employee);
+ employee = (GncEmployee *) entity;
+ gnc_ui_employee_edit (employee);
- return TRUE;
+ return TRUE;
}
static gboolean
invoiceCB (const char *location, const char *label,
gboolean new_window, GNCURLResult * result)
{
- QofInstance *entity;
- GncInvoice *invoice;
+ QofInstance *entity;
+ GncInvoice *invoice;
- /* href="...:invoice=<guid>" */
- HANDLE_TYPE ("invoice=", GNC_ID_INVOICE);
- invoice = (GncInvoice *) entity;
- gnc_ui_invoice_edit (invoice);
+ /* href="...:invoice=<guid>" */
+ HANDLE_TYPE ("invoice=", GNC_ID_INVOICE);
+ invoice = (GncInvoice *) entity;
+ gnc_ui_invoice_edit (invoice);
- return TRUE;
+ return TRUE;
}
static gboolean
jobCB (const char *location, const char *label,
- gboolean new_window, GNCURLResult * result)
+ gboolean new_window, GNCURLResult * result)
{
- QofInstance *entity;
- GncJob *job;
+ QofInstance *entity;
+ GncJob *job;
- /* href="...:job=<guid>" */
- HANDLE_TYPE ("job=", GNC_ID_JOB);
- job = (GncJob *) entity;
- gnc_ui_job_edit (job);
+ /* href="...:job=<guid>" */
+ HANDLE_TYPE ("job=", GNC_ID_JOB);
+ job = (GncJob *) entity;
+ gnc_ui_job_edit (job);
- return TRUE;
+ return TRUE;
}
/* ================================================================= */
@@ -175,160 +175,167 @@
ownerreportCB (const char *location, const char *label,
gboolean new_window, GNCURLResult * result)
{
- const char *ownerptr;
- const char *acctptr;
- GUID guid;
- GncOwner owner;
- GncOwnerType type;
- char *etype = NULL;
- Account *acc = NULL;
+ const char *ownerptr;
+ const char *acctptr;
+ GUID guid;
+ GncOwner owner;
+ GncOwnerType type;
+ char *etype = NULL;
+ Account *acc = NULL;
- g_return_val_if_fail (location != NULL, FALSE);
- g_return_val_if_fail (result != NULL, FALSE);
+ g_return_val_if_fail (location != NULL, FALSE);
+ g_return_val_if_fail (result != NULL, FALSE);
- result->load_to_stream = FALSE;
+ result->load_to_stream = FALSE;
- /* href="...:owner=<owner-type>:guid=<guid>[&acct=<guid>]" */
-
- acctptr = strchr (location, '&');
- if (acctptr)
- acctptr++;
+ /* href="...:owner=<owner-type>:guid=<guid>[&acct=<guid>]" */
- if (strncmp ("owner=", location, 6) != 0) {
- result->error_message = g_strdup_printf (_("Badly formed URL %s"),
- location);
- return FALSE;
- }
+ acctptr = strchr (location, '&');
+ if (acctptr)
+ acctptr++;
- memset (&owner, 0, sizeof (owner));
-
- ownerptr = location+6;
- switch (*ownerptr) {
- case 'c':
- type = GNC_OWNER_CUSTOMER;
- break;
- case 'v':
- type = GNC_OWNER_VENDOR;
- break;
- case 'e':
- type = GNC_OWNER_EMPLOYEE;
- break;
- case 'j':
- type = GNC_OWNER_JOB;
- break;
- default:
- result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
- return FALSE;
- }
+ if (strncmp ("owner=", location, 6) != 0)
+ {
+ result->error_message = g_strdup_printf (_("Badly formed URL %s"),
+ location);
+ return FALSE;
+ }
- if (!string_to_guid (ownerptr+2, &guid)) {
- result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
- return FALSE;
- }
+ memset (&owner, 0, sizeof (owner));
+ ownerptr = location + 6;
+ switch (*ownerptr)
+ {
+ case 'c':
+ type = GNC_OWNER_CUSTOMER;
+ break;
+ case 'v':
+ type = GNC_OWNER_VENDOR;
+ break;
+ case 'e':
+ type = GNC_OWNER_EMPLOYEE;
+ break;
+ case 'j':
+ type = GNC_OWNER_JOB;
+ break;
+ default:
+ result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
+ return FALSE;
+ }
- switch (type) {
+ if (!string_to_guid (ownerptr + 2, &guid))
+ {
+ result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
+ return FALSE;
+ }
+
+
+ switch (type)
+ {
case GNC_OWNER_CUSTOMER:
{
- GncCustomer *customer =
- gncCustomerLookup (gnc_get_current_book (), &guid);
- RETURN_IF_NULL (customer);
- gncOwnerInitCustomer (&owner, customer);
- etype = "Customer";
- break;
+ GncCustomer *customer =
+ gncCustomerLookup (gnc_get_current_book (), &guid);
+ RETURN_IF_NULL (customer);
+ gncOwnerInitCustomer (&owner, customer);
+ etype = "Customer";
+ break;
}
case GNC_OWNER_VENDOR:
{
- GncVendor *vendor =
- gncVendorLookup (gnc_get_current_book (), &guid);
- RETURN_IF_NULL (vendor);
+ GncVendor *vendor =
+ gncVendorLookup (gnc_get_current_book (), &guid);
+ RETURN_IF_NULL (vendor);
gncOwnerInitVendor (&owner, vendor);
- etype = "Vendor";
- break;
+ etype = "Vendor";
+ break;
}
case GNC_OWNER_EMPLOYEE:
{
- GncEmployee *employee =
- gncEmployeeLookup (gnc_get_current_book (), &guid);
- RETURN_IF_NULL(employee);
- gncOwnerInitEmployee (&owner, employee);
- etype = "Employee";
- break;
+ GncEmployee *employee =
+ gncEmployeeLookup (gnc_get_current_book (), &guid);
+ RETURN_IF_NULL(employee);
+ gncOwnerInitEmployee (&owner, employee);
+ etype = "Employee";
+ break;
}
case GNC_OWNER_JOB:
{
- GncJob *job =
- gncJobLookup (gnc_get_current_book (), &guid);
- RETURN_IF_NULL(job);
- gncOwnerInitJob (&owner, job);
- etype = "Job";
- break;
+ GncJob *job =
+ gncJobLookup (gnc_get_current_book (), &guid);
+ RETURN_IF_NULL(job);
+ gncOwnerInitJob (&owner, job);
+ etype = "Job";
+ break;
}
default:
- etype = "OTHER";
- }
+ etype = "OTHER";
+ }
- if (owner.owner.undefined == NULL)
- {
- result->error_message =
- g_strdup_printf (_("Entity type does not match %s: %s"),
- etype, location);
- return FALSE;
- }
-
- /* Deal with acctptr, if it exists */
- if (acctptr)
- {
- if (strncmp ("acct=", acctptr, 5) != 0)
+ if (owner.owner.undefined == NULL)
{
- result->error_message = g_strdup_printf (_("Bad URL %s"), location);
- return FALSE;
+ result->error_message =
+ g_strdup_printf (_("Entity type does not match %s: %s"),
+ etype, location);
+ return FALSE;
}
- if (!string_to_guid (acctptr+5, &guid)) {
- result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
- return FALSE;
- }
+ /* Deal with acctptr, if it exists */
+ if (acctptr)
+ {
+ if (strncmp ("acct=", acctptr, 5) != 0)
+ {
+ result->error_message = g_strdup_printf (_("Bad URL %s"), location);
+ return FALSE;
+ }
- acc = xaccAccountLookup (&guid, gnc_get_current_book ());
- if (NULL == acc)
- {
- result->error_message = g_strdup_printf (_("No such Account entity: %s"),
- location);
- return FALSE;
+ if (!string_to_guid (acctptr + 5, &guid))
+ {
+ result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
+ return FALSE;
+ }
+
+ acc = xaccAccountLookup (&guid, gnc_get_current_book ());
+ if (NULL == acc)
+ {
+ result->error_message = g_strdup_printf (_("No such Account entity: %s"),
+ location);
+ return FALSE;
+ }
}
- }
- /* Ok, let's run this report */
- gnc_business_call_owner_report (&owner, acc);
+ /* Ok, let's run this report */
+ gnc_business_call_owner_report (&owner, acc);
- return TRUE;
+ return TRUE;
}
void
gnc_business_urls_initialize (void)
{
- int i;
- static struct {
- URLType urltype;
- char * protocol;
- GncHTMLUrlCB handler;
- } types[] = {
- { GNC_ID_CUSTOMER, GNC_ID_CUSTOMER, customerCB },
- { GNC_ID_VENDOR, GNC_ID_VENDOR, vendorCB },
- { GNC_ID_EMPLOYEE, GNC_ID_EMPLOYEE, employeeCB },
- { GNC_ID_JOB, GNC_ID_JOB, jobCB },
- { GNC_ID_INVOICE, GNC_ID_INVOICE, invoiceCB },
- { URL_TYPE_OWNERREPORT, "gnc-ownerreport", ownerreportCB },
- { NULL, NULL }
- };
+ int i;
+ static struct
+ {
+ URLType urltype;
+ char * protocol;
+ GncHTMLUrlCB handler;
+ } types[] =
+ {
+ { GNC_ID_CUSTOMER, GNC_ID_CUSTOMER, customerCB },
+ { GNC_ID_VENDOR, GNC_ID_VENDOR, vendorCB },
+ { GNC_ID_EMPLOYEE, GNC_ID_EMPLOYEE, employeeCB },
+ { GNC_ID_JOB, GNC_ID_JOB, jobCB },
+ { GNC_ID_INVOICE, GNC_ID_INVOICE, invoiceCB },
+ { URL_TYPE_OWNERREPORT, "gnc-ownerreport", ownerreportCB },
+ { NULL, NULL }
+ };
- for (i = 0; types[i].urltype; i++)
- gnc_html_register_urltype (types[i].urltype, types[i].protocol);
+ for (i = 0; types[i].urltype; i++)
+ gnc_html_register_urltype (types[i].urltype, types[i].protocol);
- for (i = 0; types[i].urltype; i++)
- if (types[i].handler)
- gnc_html_register_url_handler (types[i].urltype, types[i].handler);
+ for (i = 0; types[i].urltype; i++)
+ if (types[i].handler)
+ gnc_html_register_url_handler (types[i].urltype, types[i].handler);
}
Modified: gnucash/trunk/src/business/business-gnome/dialog-billterms.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-billterms.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-billterms.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -40,10 +40,11 @@
#define DIALOG_BILLTERMS_CM_CLASS "billterms-dialog"
-enum term_cols {
- BILL_TERM_COL_NAME = 0,
- BILL_TERM_COL_TERM,
- NUM_BILL_TERM_COLS
+enum term_cols
+{
+ BILL_TERM_COL_NAME = 0,
+ BILL_TERM_COL_TERM,
+ NUM_BILL_TERM_COLS
};
void billterms_new_term_cb (GtkButton *button, BillTermsWindow *btw);
@@ -53,395 +54,413 @@
void billterms_window_destroy_cb (GtkWidget *widget, gpointer data);
void billterms_type_combobox_changed (GtkComboBox *cb, gpointer data);
-typedef struct _billterm_notebook {
- GtkTooltips * tooltips;
- GtkWidget * notebook;
+typedef struct _billterm_notebook
+{
+ GtkTooltips * tooltips;
+ GtkWidget * notebook;
- /* "Days" widgets */
- GtkWidget * days_due_days;
- GtkWidget * days_disc_days;
- GtkWidget * days_disc;
+ /* "Days" widgets */
+ GtkWidget * days_due_days;
+ GtkWidget * days_disc_days;
+ GtkWidget * days_disc;
- /* "Proximo" widgets */
- GtkWidget * prox_due_day;
- GtkWidget * prox_disc_day;
- GtkWidget * prox_disc;
- GtkWidget * prox_cutoff;
+ /* "Proximo" widgets */
+ GtkWidget * prox_due_day;
+ GtkWidget * prox_disc_day;
+ GtkWidget * prox_disc;
+ GtkWidget * prox_cutoff;
- /* What kind of term is this? */
- GncBillTermType type;
+ /* What kind of term is this? */
+ GncBillTermType type;
} BillTermNB;
-struct _billterms_window {
- GtkWidget * dialog;
- GtkWidget * terms_view;
- GtkWidget * desc_entry;
- GtkWidget * type_label;
- GtkWidget * term_vbox;
- BillTermNB notebook;
+struct _billterms_window
+{
+ GtkWidget * dialog;
+ GtkWidget * terms_view;
+ GtkWidget * desc_entry;
+ GtkWidget * type_label;
+ GtkWidget * term_vbox;
+ BillTermNB notebook;
- GncBillTerm * current_term;
- QofBook * book;
- gint component_id;
+ GncBillTerm * current_term;
+ QofBook * book;
+ gint component_id;
};
-typedef struct _new_billterms {
- GtkWidget * dialog;
- GtkWidget * name_entry;
- GtkWidget * desc_entry;
- BillTermNB notebook;
+typedef struct _new_billterms
+{
+ GtkWidget * dialog;
+ GtkWidget * name_entry;
+ GtkWidget * desc_entry;
+ BillTermNB notebook;
- BillTermsWindow * btw;
- GncBillTerm * this_term;
+ BillTermsWindow * btw;
+ GncBillTerm * this_term;
} NewBillTerm;
static GtkWidget *
read_widget (GladeXML *xml, char *name, gboolean read_only)
{
- GtkWidget *widget = glade_xml_get_widget (xml, name);
- if (read_only) {
- GtkAdjustment *adj;
- gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
- adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
- adj->step_increment = 0.0;
- adj->page_increment = 0.0;
- gtk_adjustment_changed (adj);
- }
+ GtkWidget *widget = glade_xml_get_widget (xml, name);
+ if (read_only)
+ {
+ GtkAdjustment *adj;
+ gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
+ adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
+ adj->step_increment = 0.0;
+ adj->page_increment = 0.0;
+ gtk_adjustment_changed (adj);
+ }
- return widget;
+ return widget;
}
/* NOTE: The caller needs to unref once they attach */
static void
init_notebook_widgets (BillTermNB *notebook, gboolean read_only,
- GtkDialog *dialog, gpointer user_data)
+ GtkDialog *dialog, gpointer user_data)
{
- GladeXML *xml;
- GtkWidget *parent;
+ GladeXML *xml;
+ GtkWidget *parent;
- /* Initialize the tooltips */
- notebook->tooltips = gtk_tooltips_new ();
+ /* Initialize the tooltips */
+ notebook->tooltips = gtk_tooltips_new ();
- /* Load the notebook from XML */
- xml = gnc_glade_xml_new ("billterms.glade", "Term Notebook");
- notebook->notebook = glade_xml_get_widget (xml, "term_notebook");
- parent = glade_xml_get_widget (xml, "Term Notebook");
+ /* Load the notebook from XML */
+ xml = gnc_glade_xml_new ("billterms.glade", "Term Notebook");
+ notebook->notebook = glade_xml_get_widget (xml, "term_notebook");
+ parent = glade_xml_get_widget (xml, "Term Notebook");
- /* load the "days" widgets */
- notebook->days_due_days = read_widget (xml, "days:due_days", read_only);
- notebook->days_disc_days = read_widget (xml, "days:discount_days", read_only);
- notebook->days_disc = read_widget (xml, "days:discount", read_only);
+ /* load the "days" widgets */
+ notebook->days_due_days = read_widget (xml, "days:due_days", read_only);
+ notebook->days_disc_days = read_widget (xml, "days:discount_days", read_only);
+ notebook->days_disc = read_widget (xml, "days:discount", read_only);
- /* load the "proximo" widgets */
- notebook->prox_due_day = read_widget (xml, "prox:due_day", read_only);
- notebook->prox_disc_day = read_widget (xml, "prox:discount_day", read_only);
- notebook->prox_disc = read_widget (xml, "prox:discount", read_only);
- notebook->prox_cutoff = read_widget (xml, "prox:cutoff_day", read_only);
+ /* load the "proximo" widgets */
+ notebook->prox_due_day = read_widget (xml, "prox:due_day", read_only);
+ notebook->prox_disc_day = read_widget (xml, "prox:discount_day", read_only);
+ notebook->prox_disc = read_widget (xml, "prox:discount", read_only);
+ notebook->prox_cutoff = read_widget (xml, "prox:cutoff_day", read_only);
- /* Disconnect the notebook from the window */
- g_object_ref (notebook->notebook);
- gtk_container_remove (GTK_CONTAINER (parent), notebook->notebook);
- gtk_widget_destroy (parent);
+ /* Disconnect the notebook from the window */
+ g_object_ref (notebook->notebook);
+ gtk_container_remove (GTK_CONTAINER (parent), notebook->notebook);
+ gtk_widget_destroy (parent);
- /* NOTE: The caller needs to unref once they attach */
+ /* NOTE: The caller needs to unref once they attach */
}
static void
set_numeric (GtkWidget *widget, GncBillTerm *term,
- void (*func)(GncBillTerm *, gnc_numeric))
+ void (*func)(GncBillTerm *, gnc_numeric))
{
- gnc_numeric val;
- gdouble fl = 0.0;
+ gnc_numeric val;
+ gdouble fl = 0.0;
- fl = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
- val = double_to_gnc_numeric (fl, 100000, GNC_RND_ROUND);
- func (term, val);
+ fl = gtk_spin_button_get_value (GTK_SPIN_BUTTON (widget));
+ val = double_to_gnc_numeric (fl, 100000, GNC_RND_ROUND);
+ func (term, val);
}
static void
get_numeric (GtkWidget *widget, GncBillTerm *term,
- gnc_numeric (*func)(const GncBillTerm *))
+ gnc_numeric (*func)(const GncBillTerm *))
{
- gnc_numeric val;
- gdouble fl;
+ gnc_numeric val;
+ gdouble fl;
- val = func (term);
- fl = gnc_numeric_to_double (val);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), fl);
+ val = func (term);
+ fl = gnc_numeric_to_double (val);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), fl);
}
static void
set_int (GtkWidget *widget, GncBillTerm *term,
- void (*func)(GncBillTerm *, gint))
+ void (*func)(GncBillTerm *, gint))
{
- gint val;
+ gint val;
- val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
- func (term, val);
+ val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+ func (term, val);
}
static void
get_int (GtkWidget *widget, GncBillTerm *term,
- gint (*func)(const GncBillTerm *))
+ gint (*func)(const GncBillTerm *))
{
- gint val;
+ gint val;
- val = func (term);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gfloat)val);
+ val = func (term);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gfloat)val);
}
/* return TRUE if anything truly changed */
static gboolean
ui_to_billterm (NewBillTerm *nbt)
{
- BillTermNB *notebook;
- GncBillTerm *term;
- const char *text;
+ BillTermNB *notebook;
+ GncBillTerm *term;
+ const char *text;
- term = nbt->this_term;
- notebook = &nbt->notebook;
+ term = nbt->this_term;
+ notebook = &nbt->notebook;
- text = gtk_entry_get_text (GTK_ENTRY (nbt->desc_entry));
- if (text)
- gncBillTermSetDescription (term, text);
+ text = gtk_entry_get_text (GTK_ENTRY (nbt->desc_entry));
+ if (text)
+ gncBillTermSetDescription (term, text);
- gncBillTermSetType (nbt->this_term, nbt->notebook.type);
+ gncBillTermSetType (nbt->this_term, nbt->notebook.type);
- switch (nbt->notebook.type) {
- case GNC_TERM_TYPE_DAYS:
- set_int (notebook->days_due_days, term, gncBillTermSetDueDays);
- set_int (notebook->days_disc_days, term, gncBillTermSetDiscountDays);
- set_numeric (notebook->days_disc, term, gncBillTermSetDiscount);
- break;
+ switch (nbt->notebook.type)
+ {
+ case GNC_TERM_TYPE_DAYS:
+ set_int (notebook->days_due_days, term, gncBillTermSetDueDays);
+ set_int (notebook->days_disc_days, term, gncBillTermSetDiscountDays);
+ set_numeric (notebook->days_disc, term, gncBillTermSetDiscount);
+ break;
- case GNC_TERM_TYPE_PROXIMO:
- set_int (notebook->prox_due_day, term, gncBillTermSetDueDays);
- set_int (notebook->prox_disc_day, term, gncBillTermSetDiscountDays);
- set_numeric (notebook->prox_disc, term, gncBillTermSetDiscount);
- set_int (notebook->prox_cutoff, term, gncBillTermSetCutoff);
- break;
- }
+ case GNC_TERM_TYPE_PROXIMO:
+ set_int (notebook->prox_due_day, term, gncBillTermSetDueDays);
+ set_int (notebook->prox_disc_day, term, gncBillTermSetDiscountDays);
+ set_numeric (notebook->prox_disc, term, gncBillTermSetDiscount);
+ set_int (notebook->prox_cutoff, term, gncBillTermSetCutoff);
+ break;
+ }
- return gncBillTermIsDirty (term);
+ return gncBillTermIsDirty (term);
}
static void
billterm_to_ui (GncBillTerm *term, GtkWidget *desc, BillTermNB *notebook)
{
- gtk_entry_set_text (GTK_ENTRY (desc), gncBillTermGetDescription (term));
- notebook->type = gncBillTermGetType (term);
+ gtk_entry_set_text (GTK_ENTRY (desc), gncBillTermGetDescription (term));
+ notebook->type = gncBillTermGetType (term);
- switch (notebook->type) {
- case GNC_TERM_TYPE_DAYS:
- get_int (notebook->days_due_days, term, gncBillTermGetDueDays);
- get_int (notebook->days_disc_days, term, gncBillTermGetDiscountDays);
- get_numeric (notebook->days_disc, term, gncBillTermGetDiscount);
- break;
+ switch (notebook->type)
+ {
+ case GNC_TERM_TYPE_DAYS:
+ get_int (notebook->days_due_days, term, gncBillTermGetDueDays);
+ get_int (notebook->days_disc_days, term, gncBillTermGetDiscountDays);
+ get_numeric (notebook->days_disc, term, gncBillTermGetDiscount);
+ break;
- case GNC_TERM_TYPE_PROXIMO:
- get_int (notebook->prox_due_day, term, gncBillTermGetDueDays);
- get_int (notebook->prox_disc_day, term, gncBillTermGetDiscountDays);
- get_numeric (notebook->prox_disc, term, gncBillTermGetDiscount);
- get_int (notebook->prox_cutoff, term, gncBillTermGetCutoff);
- break;
- }
+ case GNC_TERM_TYPE_PROXIMO:
+ get_int (notebook->prox_due_day, term, gncBillTermGetDueDays);
+ get_int (notebook->prox_disc_day, term, gncBillTermGetDiscountDays);
+ get_numeric (notebook->prox_disc, term, gncBillTermGetDiscount);
+ get_int (notebook->prox_cutoff, term, gncBillTermGetCutoff);
+ break;
+ }
}
static gboolean
verify_term_ok (NewBillTerm *nbt)
{
- char *message;
- gnc_numeric num;
+ char *message;
+ gnc_numeric num;
- return TRUE;
+ return TRUE;
- /* verify the discount day(s) is less than the due day(s) */
- num = gnc_numeric_zero ();
- if (gnc_numeric_negative_p (num)) {
- message = _("Negative amounts are not allowed.");
- gnc_error_dialog (nbt->dialog, "%s", message);
- return FALSE;
- }
- if (gnc_numeric_compare (num, gnc_numeric_create (100, 1)) > 0) {
- message = _("Percentage amount must be between 0 and 100.");
- gnc_error_dialog (nbt->dialog, "%s", message);
- return FALSE;
- }
- return TRUE;
+ /* verify the discount day(s) is less than the due day(s) */
+ num = gnc_numeric_zero ();
+ if (gnc_numeric_negative_p (num))
+ {
+ message = _("Negative amounts are not allowed.");
+ gnc_error_dialog (nbt->dialog, "%s", message);
+ return FALSE;
+ }
+ if (gnc_numeric_compare (num, gnc_numeric_create (100, 1)) > 0)
+ {
+ message = _("Percentage amount must be between 0 and 100.");
+ gnc_error_dialog (nbt->dialog, "%s", message);
+ return FALSE;
+ }
+ return TRUE;
}
static gboolean
new_billterm_ok_cb (NewBillTerm *nbt)
{
- BillTermsWindow *btw;
- const char *name = NULL;
- char *message;
+ BillTermsWindow *btw;
+ const char *name = NULL;
+ char *message;
- g_return_val_if_fail (nbt, FALSE);
- btw = nbt->btw;
+ g_return_val_if_fail (nbt, FALSE);
+ btw = nbt->btw;
- /* Verify that we've got real, valid data */
+ /* Verify that we've got real, valid data */
- /* verify the name, maybe */
- if (nbt->this_term == NULL) {
- name = gtk_entry_get_text (GTK_ENTRY (nbt->name_entry));
- if (name == NULL || *name == '\0') {
- message = _("You must provide a name for this Billing Term.");
- gnc_error_dialog (nbt->dialog, "%s", message);
- return FALSE;
+ /* verify the name, maybe */
+ if (nbt->this_term == NULL)
+ {
+ name = gtk_entry_get_text (GTK_ENTRY (nbt->name_entry));
+ if (name == NULL || *name == '\0')
+ {
+ message = _("You must provide a name for this Billing Term.");
+ gnc_error_dialog (nbt->dialog, "%s", message);
+ return FALSE;
+ }
+ if (gncBillTermLookupByName (btw->book, name))
+ {
+ message = g_strdup_printf(_(
+ "You must provide a unique name for this Billing Term. "
+ "Your choice \"%s\" is already in use."), name);
+ gnc_error_dialog (nbt->dialog, "%s", message);
+ g_free (message);
+ return FALSE;
+ }
}
- if (gncBillTermLookupByName (btw->book, name)) {
- message = g_strdup_printf(_(
- "You must provide a unique name for this Billing Term. "
- "Your choice \"%s\" is already in use."), name);
- gnc_error_dialog (nbt->dialog, "%s", message);
- g_free (message);
- return FALSE;
- }
- }
- /* Verify the actual data */
- if (!verify_term_ok (nbt))
- return FALSE;
+ /* Verify the actual data */
+ if (!verify_term_ok (nbt))
+ return FALSE;
- gnc_suspend_gui_refresh ();
+ gnc_suspend_gui_refresh ();
- /* Ok, it's all valid, now either change or add this thing */
- if (nbt->this_term == NULL) {
- nbt->this_term = gncBillTermCreate (btw->book);
- gncBillTermBeginEdit (nbt->this_term);
- gncBillTermSetName (nbt->this_term, name);
- /* Reset the current term */
- btw->current_term = nbt->this_term;
- } else
- gncBillTermBeginEdit (btw->current_term);
+ /* Ok, it's all valid, now either change or add this thing */
+ if (nbt->this_term == NULL)
+ {
+ nbt->this_term = gncBillTermCreate (btw->book);
+ gncBillTermBeginEdit (nbt->this_term);
+ gncBillTermSetName (nbt->this_term, name);
+ /* Reset the current term */
+ btw->current_term = nbt->this_term;
+ }
+ else
+ gncBillTermBeginEdit (btw->current_term);
- /* Fill in the rest of the term */
- if (ui_to_billterm (nbt))
- gncBillTermChanged (btw->current_term);
+ /* Fill in the rest of the term */
+ if (ui_to_billterm (nbt))
+ gncBillTermChanged (btw->current_term);
- /* Mark the table as changed and commit it */
- gncBillTermCommitEdit (btw->current_term);
+ /* Mark the table as changed and commit it */
+ gncBillTermCommitEdit (btw->current_term);
- gnc_resume_gui_refresh();
- return TRUE;
+ gnc_resume_gui_refresh();
+ return TRUE;
}
static void
show_notebook (BillTermNB *notebook)
{
- g_return_if_fail (notebook->type > 0);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook->notebook),
- notebook->type-1);
+ g_return_if_fail (notebook->type > 0);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook->notebook),
+ notebook->type - 1);
}
static void
maybe_set_type (NewBillTerm *nbt, GncBillTermType type)
{
- /* See if anything to do? */
- if (type == nbt->notebook.type)
- return;
+ /* See if anything to do? */
+ if (type == nbt->notebook.type)
+ return;
- /* Yep. Let's refresh */
- nbt->notebook.type = type;
- show_notebook (&nbt->notebook);
+ /* Yep. Let's refresh */
+ nbt->notebook.type = type;
+ show_notebook (&nbt->notebook);
}
void
billterms_type_combobox_changed (GtkComboBox *cb, gpointer data)
{
- NewBillTerm *nbt = data;
- gint value;
+ NewBillTerm *nbt = data;
+ gint value;
- value = gtk_combo_box_get_active(cb);
- maybe_set_type (nbt, value + 1);
+ value = gtk_combo_box_get_active(cb);
+ maybe_set_type (nbt, value + 1);
}
static GncBillTerm *
new_billterm_dialog (BillTermsWindow *btw, GncBillTerm *term,
- const char *name)
+ const char *name)
{
- GncBillTerm *created_term = NULL;
- NewBillTerm *nbt;
- GladeXML *xml;
- GtkWidget *box, *combo_box;
- gint response;
- gboolean done;
- const gchar *dialog_name;
+ GncBillTerm *created_term = NULL;
+ NewBillTerm *nbt;
+ GladeXML *xml;
+ GtkWidget *box, *combo_box;
+ gint response;
+ gboolean done;
+ const gchar *dialog_name;
- if (!btw) return NULL;
+ if (!btw) return NULL;
- nbt = g_new0 (NewBillTerm, 1);
- nbt->btw = btw;
- nbt->this_term = term;
+ nbt = g_new0 (NewBillTerm, 1);
+ nbt->btw = btw;
+ nbt->this_term = term;
- /* Open and read the XML */
- dialog_name = term ? "Edit Term Dialog" : "New Term Dialog";
- xml = gnc_glade_xml_new ("billterms.glade", dialog_name);
- nbt->dialog = glade_xml_get_widget (xml, dialog_name);
- nbt->name_entry = glade_xml_get_widget (xml, "name_entry");
- nbt->desc_entry = glade_xml_get_widget (xml, "desc_entry");
- if (name)
- gtk_entry_set_text (GTK_ENTRY (nbt->name_entry), name);
+ /* Open and read the XML */
+ dialog_name = term ? "Edit Term Dialog" : "New Term Dialog";
+ xml = gnc_glade_xml_new ("billterms.glade", dialog_name);
+ nbt->dialog = glade_xml_get_widget (xml, dialog_name);
+ nbt->name_entry = glade_xml_get_widget (xml, "name_entry");
+ nbt->desc_entry = glade_xml_get_widget (xml, "desc_entry");
+ if (name)
+ gtk_entry_set_text (GTK_ENTRY (nbt->name_entry), name);
- /* Initialize the notebook widgets */
- init_notebook_widgets (&nbt->notebook, FALSE,
- GTK_DIALOG (nbt->dialog), nbt);
+ /* Initialize the notebook widgets */
+ init_notebook_widgets (&nbt->notebook, FALSE,
+ GTK_DIALOG (nbt->dialog), nbt);
- /* Attach the notebook */
- box = glade_xml_get_widget (xml, "notebook_box");
- gtk_box_pack_start (GTK_BOX (box), nbt->notebook.notebook, TRUE, TRUE, 0);
- g_object_unref (nbt->notebook.notebook);
+ /* Attach the notebook */
+ box = glade_xml_get_widget (xml, "notebook_box");
+ gtk_box_pack_start (GTK_BOX (box), nbt->notebook.notebook, TRUE, TRUE, 0);
+ g_object_unref (nbt->notebook.notebook);
- /* Fill in the widgets appropriately */
- if (term)
- billterm_to_ui (term, nbt->desc_entry, &nbt->notebook);
- else
- nbt->notebook.type = GNC_TERM_TYPE_DAYS;
+ /* Fill in the widgets appropriately */
+ if (term)
+ billterm_to_ui (term, nbt->desc_entry, &nbt->notebook);
+ else
+ nbt->notebook.type = GNC_TERM_TYPE_DAYS;
- /* Create the menu */
- combo_box = glade_xml_get_widget (xml, "type_combobox");
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), nbt->notebook.type - 1);
+ /* Create the menu */
+ combo_box = glade_xml_get_widget (xml, "type_combobox");
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), nbt->notebook.type - 1);
- /* Show the right notebook page */
- show_notebook (&nbt->notebook);
+ /* Show the right notebook page */
+ show_notebook (&nbt->notebook);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- nbt);
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ nbt);
- gtk_window_set_transient_for (GTK_WINDOW(nbt->dialog),
- GTK_WINDOW(btw->dialog));
+ gtk_window_set_transient_for (GTK_WINDOW(nbt->dialog),
+ GTK_WINDOW(btw->dialog));
- /* Show what we should */
- gtk_widget_show_all (nbt->dialog);
- if (term) {
- gtk_widget_grab_focus (nbt->desc_entry);
- } else
- gtk_widget_grab_focus (nbt->name_entry);
+ /* Show what we should */
+ gtk_widget_show_all (nbt->dialog);
+ if (term)
+ {
+ gtk_widget_grab_focus (nbt->desc_entry);
+ }
+ else
+ gtk_widget_grab_focus (nbt->name_entry);
- done = FALSE;
- while (!done) {
- response = gtk_dialog_run (GTK_DIALOG (nbt->dialog));
- switch (response) {
- case GTK_RESPONSE_OK:
- if (new_billterm_ok_cb (nbt)) {
- created_term = nbt->this_term;
- done = TRUE;
- }
- break;
- default:
- done = TRUE;
- break;
+ done = FALSE;
+ while (!done)
+ {
+ response = gtk_dialog_run (GTK_DIALOG (nbt->dialog));
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ if (new_billterm_ok_cb (nbt))
+ {
+ created_term = nbt->this_term;
+ done = TRUE;
+ }
+ break;
+ default:
+ done = TRUE;
+ break;
+ }
}
- }
- gtk_widget_destroy(nbt->dialog);
- g_free(nbt);
+ gtk_widget_destroy(nbt->dialog);
+ g_free(nbt);
- return created_term;
+ return created_term;
}
/***********************************************************************/
@@ -449,312 +468,324 @@
static void
billterms_term_refresh (BillTermsWindow *btw)
{
- char *type_label;
+ char *type_label;
- g_return_if_fail (btw);
+ g_return_if_fail (btw);
- if (!btw->current_term) {
- gtk_widget_hide_all (btw->term_vbox);
- return;
- }
+ if (!btw->current_term)
+ {
+ gtk_widget_hide_all (btw->term_vbox);
+ return;
+ }
- gtk_widget_show_all (btw->term_vbox);
- billterm_to_ui (btw->current_term, btw->desc_entry, &btw->notebook);
- switch (gncBillTermGetType (btw->current_term)) {
- case GNC_TERM_TYPE_DAYS:
- type_label = _("Days");
- break;
- case GNC_TERM_TYPE_PROXIMO:
- type_label = _("Proximo");
- break;
- default:
- type_label = _("Unknown");
- break;
- }
- show_notebook (&btw->notebook);
- gtk_label_set_text (GTK_LABEL (btw->type_label), type_label);
+ gtk_widget_show_all (btw->term_vbox);
+ billterm_to_ui (btw->current_term, btw->desc_entry, &btw->notebook);
+ switch (gncBillTermGetType (btw->current_term))
+ {
+ case GNC_TERM_TYPE_DAYS:
+ type_label = _("Days");
+ break;
+ case GNC_TERM_TYPE_PROXIMO:
+ type_label = _("Proximo");
+ break;
+ default:
+ type_label = _("Unknown");
+ break;
+ }
+ show_notebook (&btw->notebook);
+ gtk_label_set_text (GTK_LABEL (btw->type_label), type_label);
}
static void
billterms_window_refresh (BillTermsWindow *btw)
{
- GList *list, *node;
- GncBillTerm *term;
- GtkTreeView *view;
- GtkListStore *store;
- GtkTreeIter iter;
- GtkTreePath *path;
- GtkTreeSelection *selection;
- GtkTreeRowReference *reference = NULL;
+ GList *list, *node;
+ GncBillTerm *term;
+ GtkTreeView *view;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeSelection *selection;
+ GtkTreeRowReference *reference = NULL;
- g_return_if_fail (btw);
- view = GTK_TREE_VIEW (btw->terms_view);
- store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
+ g_return_if_fail (btw);
+ view = GTK_TREE_VIEW (btw->terms_view);
+ store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
- /* Clear the list */
- gtk_list_store_clear (store);
- gnc_gui_component_clear_watches (btw->component_id);
+ /* Clear the list */
+ gtk_list_store_clear (store);
+ gnc_gui_component_clear_watches (btw->component_id);
- /* Add the items to the list */
- list = gncBillTermGetTerms (btw->book);
+ /* Add the items to the list */
+ list = gncBillTermGetTerms (btw->book);
- /* If there are no terms, clear the term display */
- if (list == NULL) {
- btw->current_term = NULL;
- billterms_term_refresh (btw);
- } else {
- list = g_list_reverse (g_list_copy (list));
- }
+ /* If there are no terms, clear the term display */
+ if (list == NULL)
+ {
+ btw->current_term = NULL;
+ billterms_term_refresh (btw);
+ }
+ else
+ {
+ list = g_list_reverse (g_list_copy (list));
+ }
- for ( node = list; node; node = node->next) {
- term = node->data;
- gnc_gui_component_watch_entity (btw->component_id,
- gncBillTermGetGUID (term),
- QOF_EVENT_MODIFY);
+ for ( node = list; node; node = node->next)
+ {
+ term = node->data;
+ gnc_gui_component_watch_entity (btw->component_id,
+ gncBillTermGetGUID (term),
+ QOF_EVENT_MODIFY);
- gtk_list_store_prepend(store, &iter);
- gtk_list_store_set(store, &iter,
- BILL_TERM_COL_NAME, gncBillTermGetName(term),
- BILL_TERM_COL_TERM, term,
- -1);
- if (term == btw->current_term) {
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
- reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), path);
- gtk_tree_path_free(path);
+ gtk_list_store_prepend(store, &iter);
+ gtk_list_store_set(store, &iter,
+ BILL_TERM_COL_NAME, gncBillTermGetName(term),
+ BILL_TERM_COL_TERM, term,
+ -1);
+ if (term == btw->current_term)
+ {
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
+ reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), path);
+ gtk_tree_path_free(path);
+ }
}
- }
- g_list_free (list);
+ g_list_free (list);
- gnc_gui_component_watch_entity_type (btw->component_id,
- GNC_BILLTERM_MODULE_NAME,
- QOF_EVENT_CREATE | QOF_EVENT_DESTROY);
+ gnc_gui_component_watch_entity_type (btw->component_id,
+ GNC_BILLTERM_MODULE_NAME,
+ QOF_EVENT_CREATE | QOF_EVENT_DESTROY);
- if (reference) {
- path = gtk_tree_row_reference_get_path(reference);
- gtk_tree_row_reference_free(reference);
- if (path) {
- selection = gtk_tree_view_get_selection(view);
- gtk_tree_selection_select_path(selection, path);
- gtk_tree_view_scroll_to_cell(view, path, NULL, TRUE, 0.5, 0.0);
- gtk_tree_path_free(path);
+ if (reference)
+ {
+ path = gtk_tree_row_reference_get_path(reference);
+ gtk_tree_row_reference_free(reference);
+ if (path)
+ {
+ selection = gtk_tree_view_get_selection(view);
+ gtk_tree_selection_select_path(selection, path);
+ gtk_tree_view_scroll_to_cell(view, path, NULL, TRUE, 0.5, 0.0);
+ gtk_tree_path_free(path);
+ }
}
- }
}
static void
billterm_selection_changed (GtkTreeSelection *selection,
- BillTermsWindow *btw)
+ BillTermsWindow *btw)
{
- GncBillTerm *term = NULL;
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GncBillTerm *term = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- g_return_if_fail (btw);
+ g_return_if_fail (btw);
- if (gtk_tree_selection_get_selected(selection, &model, &iter))
- gtk_tree_model_get(model, &iter, BILL_TERM_COL_TERM, &term, -1);
+ if (gtk_tree_selection_get_selected(selection, &model, &iter))
+ gtk_tree_model_get(model, &iter, BILL_TERM_COL_TERM, &term, -1);
- /* If we've changed, then reset the term list */
- if (term != btw->current_term)
- btw->current_term = term;
+ /* If we've changed, then reset the term list */
+ if (term != btw->current_term)
+ btw->current_term = term;
- /* And force a refresh of the entries */
- billterms_term_refresh (btw);
+ /* And force a refresh of the entries */
+ billterms_term_refresh (btw);
}
static void
billterm_selection_activated (GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- BillTermsWindow *btw)
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ BillTermsWindow *btw)
{
- new_billterm_dialog (btw, btw->current_term, NULL);
+ new_billterm_dialog (btw, btw->current_term, NULL);
}
void
billterms_new_term_cb (GtkButton *button, BillTermsWindow *btw)
{
- g_return_if_fail (btw);
- new_billterm_dialog (btw, NULL, NULL);
+ g_return_if_fail (btw);
+ new_billterm_dialog (btw, NULL, NULL);
}
void
billterms_delete_term_cb (GtkButton *button, BillTermsWindow *btw)
{
- g_return_if_fail (btw);
+ g_return_if_fail (btw);
- if (!btw->current_term)
- return;
+ if (!btw->current_term)
+ return;
- if (gncBillTermGetRefcount (btw->current_term) > 0) {
- gnc_error_dialog (btw->dialog,
- _("Term \"%s\" is in use. You cannot delete it."),
- gncBillTermGetName (btw->current_term));
- return;
- }
+ if (gncBillTermGetRefcount (btw->current_term) > 0)
+ {
+ gnc_error_dialog (btw->dialog,
+ _("Term \"%s\" is in use. You cannot delete it."),
+ gncBillTermGetName (btw->current_term));
+ return;
+ }
- if (gnc_verify_dialog (btw->dialog, FALSE,
- _("Are you sure you want to delete \"%s\"?"),
- gncBillTermGetName (btw->current_term))) {
- /* Ok, let's remove it */
- gnc_suspend_gui_refresh ();
- gncBillTermBeginEdit (btw->current_term);
- gncBillTermDestroy (btw->current_term);
- btw->current_term = NULL;
- gnc_resume_gui_refresh ();
- }
+ if (gnc_verify_dialog (btw->dialog, FALSE,
+ _("Are you sure you want to delete \"%s\"?"),
+ gncBillTermGetName (btw->current_term)))
+ {
+ /* Ok, let's remove it */
+ gnc_suspend_gui_refresh ();
+ gncBillTermBeginEdit (btw->current_term);
+ gncBillTermDestroy (btw->current_term);
+ btw->current_term = NULL;
+ gnc_resume_gui_refresh ();
+ }
}
void
billterms_edit_term_cb (GtkButton *button, BillTermsWindow *btw)
{
- g_return_if_fail (btw);
- if (!btw->current_term)
- return;
- new_billterm_dialog (btw, btw->current_term, NULL);
+ g_return_if_fail (btw);
+ if (!btw->current_term)
+ return;
+ new_billterm_dialog (btw, btw->current_term, NULL);
}
static void
billterms_window_refresh_handler (GHashTable *changes, gpointer data)
{
- BillTermsWindow *btw = data;
+ BillTermsWindow *btw = data;
- g_return_if_fail (data);
- billterms_window_refresh (btw);
+ g_return_if_fail (data);
+ billterms_window_refresh (btw);
}
static void
billterms_window_close_handler (gpointer data)
{
- BillTermsWindow *btw = data;
- g_return_if_fail (btw);
+ BillTermsWindow *btw = data;
+ g_return_if_fail (btw);
- gtk_widget_destroy (btw->dialog);
+ gtk_widget_destroy (btw->dialog);
}
void
billterms_window_close (GtkWidget *widget, gpointer data)
{
- BillTermsWindow *btw = data;
+ BillTermsWindow *btw = data;
- gnc_ui_billterms_window_destroy (btw);
+ gnc_ui_billterms_window_destroy (btw);
}
void
billterms_window_destroy_cb (GtkWidget *widget, gpointer data)
{
- BillTermsWindow *btw = data;
+ BillTermsWindow *btw = data;
- if (!btw) return;
+ if (!btw) return;
- gnc_unregister_gui_component (btw->component_id);
+ gnc_unregister_gui_component (btw->component_id);
- g_free (btw);
+ g_free (btw);
}
static gboolean
find_handler (gpointer find_data, gpointer user_data)
{
- BillTermsWindow *btw = user_data;
- QofBook *book = find_data;
+ BillTermsWindow *btw = user_data;
+ QofBook *book = find_data;
- return (btw != NULL && btw->book == book);
+ return (btw != NULL && btw->book == book);
}
/* Create a billterms window */
BillTermsWindow *
gnc_ui_billterms_window_new (QofBook *book)
{
- BillTermsWindow *btw;
- GladeXML *xml;
- GtkWidget *widget;
- GtkTreeView *view;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkListStore *store;
- GtkTreeSelection *selection;
+ BillTermsWindow *btw;
+ GladeXML *xml;
+ GtkWidget *widget;
+ GtkTreeView *view;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+ GtkListStore *store;
+ GtkTreeSelection *selection;
- if (!book) return NULL;
+ if (!book) return NULL;
- /*
- * Find an existing billterm window. If found, bring it to
- * the front. If we have an actual owner, then set it in
- * the window.
- */
- btw = gnc_find_first_gui_component (DIALOG_BILLTERMS_CM_CLASS,
- find_handler, book);
- if (btw) {
- gtk_window_present (GTK_WINDOW(btw->dialog));
- return btw;
- }
+ /*
+ * Find an existing billterm window. If found, bring it to
+ * the front. If we have an actual owner, then set it in
+ * the window.
+ */
+ btw = gnc_find_first_gui_component (DIALOG_BILLTERMS_CM_CLASS,
+ find_handler, book);
+ if (btw)
+ {
+ gtk_window_present (GTK_WINDOW(btw->dialog));
+ return btw;
+ }
- /* Didn't find one -- create a new window */
- btw = g_new0 (BillTermsWindow, 1);
- btw->book = book;
+ /* Didn't find one -- create a new window */
+ btw = g_new0 (BillTermsWindow, 1);
+ btw->book = book;
- /* Open and read the XML */
- xml = gnc_glade_xml_new ("billterms.glade", "Terms Window");
- btw->dialog = glade_xml_get_widget (xml, "Terms Window");
- btw->terms_view = glade_xml_get_widget (xml, "terms_view");
- btw->desc_entry = glade_xml_get_widget (xml, "desc_entry");
- btw->type_label = glade_xml_get_widget (xml, "type_label");
- btw->term_vbox = glade_xml_get_widget (xml, "term_vbox");
+ /* Open and read the XML */
+ xml = gnc_glade_xml_new ("billterms.glade", "Terms Window");
+ btw->dialog = glade_xml_get_widget (xml, "Terms Window");
+ btw->terms_view = glade_xml_get_widget (xml, "terms_view");
+ btw->desc_entry = glade_xml_get_widget (xml, "desc_entry");
+ btw->type_label = glade_xml_get_widget (xml, "type_label");
+ btw->term_vbox = glade_xml_get_widget (xml, "term_vbox");
- /* Initialize the view */
- view = GTK_TREE_VIEW(btw->terms_view);
- store = gtk_list_store_new (NUM_BILL_TERM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
- gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
- g_object_unref(store);
+ /* Initialize the view */
+ view = GTK_TREE_VIEW(btw->terms_view);
+ store = gtk_list_store_new (NUM_BILL_TERM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
+ gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
+ g_object_unref(store);
- renderer = gtk_cell_renderer_text_new();
- column = gtk_tree_view_column_new_with_attributes("", renderer,
- "text", BILL_TERM_COL_NAME,
- NULL);
- gtk_tree_view_append_column(view, column);
+ renderer = gtk_cell_renderer_text_new();
+ column = gtk_tree_view_column_new_with_attributes("", renderer,
+ "text", BILL_TERM_COL_NAME,
+ NULL);
+ gtk_tree_view_append_column(view, column);
- g_signal_connect(view, "row-activated",
- G_CALLBACK(billterm_selection_activated), btw);
- selection = gtk_tree_view_get_selection(view);
- g_signal_connect(selection, "changed",
- G_CALLBACK(billterm_selection_changed), btw);
+ g_signal_connect(view, "row-activated",
+ G_CALLBACK(billterm_selection_activated), btw);
+ selection = gtk_tree_view_get_selection(view);
+ g_signal_connect(selection, "changed",
+ G_CALLBACK(billterm_selection_changed), btw);
- /* Initialize the notebook widgets */
- init_notebook_widgets (&btw->notebook, TRUE,
- GTK_DIALOG (btw->dialog), btw);
+ /* Initialize the notebook widgets */
+ init_notebook_widgets (&btw->notebook, TRUE,
+ GTK_DIALOG (btw->dialog), btw);
- /* Attach the notebook */
- widget = glade_xml_get_widget (xml, "notebook_box");
- gtk_box_pack_start (GTK_BOX (widget), btw->notebook.notebook,
- TRUE, TRUE, 0);
- g_object_unref (btw->notebook.notebook);
+ /* Attach the notebook */
+ widget = glade_xml_get_widget (xml, "notebook_box");
+ gtk_box_pack_start (GTK_BOX (widget), btw->notebook.notebook,
+ TRUE, TRUE, 0);
+ g_object_unref (btw->notebook.notebook);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- btw);
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ btw);
- /* register with component manager */
- btw->component_id =
- gnc_register_gui_component (DIALOG_BILLTERMS_CM_CLASS,
- billterms_window_refresh_handler,
- billterms_window_close_handler,
- btw);
+ /* register with component manager */
+ btw->component_id =
+ gnc_register_gui_component (DIALOG_BILLTERMS_CM_CLASS,
+ billterms_window_refresh_handler,
+ billterms_window_close_handler,
+ btw);
- gtk_widget_show_all (btw->dialog);
- billterms_window_refresh (btw);
+ gtk_widget_show_all (btw->dialog);
+ billterms_window_refresh (btw);
- return btw;
+ return btw;
}
/* Destroy a billterms window */
void
gnc_ui_billterms_window_destroy (BillTermsWindow *btw)
{
- if (!btw)
- return;
+ if (!btw)
+ return;
- gnc_close_gui_component (btw->component_id);
+ gnc_close_gui_component (btw->component_id);
}
#if 0
@@ -762,13 +793,13 @@
GncBillTerm *
gnc_ui_billterms_new_from_name (QofBook *book, const char *name)
{
- BillTermsWindow *btw;
+ BillTermsWindow *btw;
- if (!book) return NULL;
+ if (!book) return NULL;
- btw = gnc_ui_billterms_window_new (book);
- if (!btw) return NULL;
+ btw = gnc_ui_billterms_window_new (book);
+ if (!btw) return NULL;
- return new_billterm_dialog (btw, NULL, name);
+ return new_billterm_dialog (btw, NULL, name);
}
#endif
Modified: gnucash/trunk/src/business/business-gnome/dialog-choose-owner.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-choose-owner.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-choose-owner.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -34,71 +34,75 @@
#include "dialog-choose-owner.h"
#include "business-gnome-utils.h"
-struct _choose_owner_dialog {
- GtkWidget * dialog;
- GtkWidget * owner_choice;
- QofBook * book;
- GncOwner owner;
- Split * split;
+struct _choose_owner_dialog
+{
+ GtkWidget * dialog;
+ GtkWidget * owner_choice;
+ QofBook * book;
+ GncOwner owner;
+ Split * split;
};
static DialogChooseOwner *
gcoi_create_dialog(Split* split)
{
- DialogChooseOwner* dco;
- GladeXML *xml;
- GtkWidget *widget, *box;
+ DialogChooseOwner* dco;
+ GladeXML *xml;
+ GtkWidget *widget, *box;
- g_return_val_if_fail(split, NULL);
+ g_return_val_if_fail(split, NULL);
- dco = g_new0(DialogChooseOwner, 1);
- g_assert(dco);
- dco->book = qof_instance_get_book(QOF_INSTANCE(split));
- dco->split = split;
+ dco = g_new0(DialogChooseOwner, 1);
+ g_assert(dco);
+ dco->book = qof_instance_get_book(QOF_INSTANCE(split));
+ dco->split = split;
- /* Open the Glade file */
- xml = gnc_glade_xml_new("choose-owner.glade", "Choose Owner Dialog");
- g_assert(xml);
+ /* Open the Glade file */
+ xml = gnc_glade_xml_new("choose-owner.glade", "Choose Owner Dialog");
+ g_assert(xml);
- /* Get the dialog handle */
- dco->dialog = glade_xml_get_widget(xml, "Choose Owner Dialog");
- g_assert(dco->dialog);
+ /* Get the dialog handle */
+ dco->dialog = glade_xml_get_widget(xml, "Choose Owner Dialog");
+ g_assert(dco->dialog);
- /* Get the title widget and set the title */
- widget = glade_xml_get_widget(xml, "title_label");
- if (1 == 1) {
- gncOwnerInitCustomer(&(dco->owner), NULL);
+ /* Get the title widget and set the title */
+ widget = glade_xml_get_widget(xml, "title_label");
+ if (1 == 1)
+ {
+ gncOwnerInitCustomer(&(dco->owner), NULL);
+ gtk_label_set_text(GTK_LABEL(widget),
+ _("This transaction needs to be assigned to a Customer."
+ " Please choose the Customer below."));
+ }
+ else
+ {
+ gncOwnerInitVendor(&(dco->owner), NULL);
+ gtk_label_set_text(GTK_LABEL(widget),
+ _("This transaction needs to be assigned to a Vendor."
+ " Please choose the Vendor below."));
+ }
+
+ /* Get the transaction description and set it */
+ widget = glade_xml_get_widget(xml, "desc_label");
gtk_label_set_text(GTK_LABEL(widget),
- _("This transaction needs to be assigned to a Customer."
- " Please choose the Customer below."));
- } else {
- gncOwnerInitVendor(&(dco->owner), NULL);
- gtk_label_set_text(GTK_LABEL(widget),
- _("This transaction needs to be assigned to a Vendor."
- " Please choose the Vendor below."));
- }
+ xaccTransGetDescription(xaccSplitGetParent(split)));
- /* Get the transaction description and set it */
- widget = glade_xml_get_widget(xml, "desc_label");
- gtk_label_set_text(GTK_LABEL(widget),
- xaccTransGetDescription(xaccSplitGetParent(split)));
+ /* Get the owner label and the owner box */
+ widget = glade_xml_get_widget(xml, "owner_label");
+ box = glade_xml_get_widget(xml, "owner_box");
+ dco->owner_choice = gnc_owner_select_create(widget, box, dco->book,
+ &(dco->owner));
- /* Get the owner label and the owner box */
- widget = glade_xml_get_widget(xml, "owner_label");
- box = glade_xml_get_widget(xml, "owner_box");
- dco->owner_choice = gnc_owner_select_create(widget, box, dco->book,
- &(dco->owner));
-
- gtk_widget_show_all(dco->dialog);
- return dco;
+ gtk_widget_show_all(dco->dialog);
+ return dco;
}
gboolean
gnc_split_assign_owner(GtkWidget* window, Split* split)
{
- if (1 == 0)
- gcoi_create_dialog(split);
+ if (1 == 0)
+ gcoi_create_dialog(split);
- return FALSE;
+ return FALSE;
}
Modified: gnucash/trunk/src/business/business-gnome/dialog-customer.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-customer.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-customer.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -55,7 +55,7 @@
#define GCONF_SECTION_SEARCH "dialogs/business/customer_search"
void gnc_customer_taxtable_check_cb (GtkToggleButton *togglebutton,
- gpointer user_data);
+ gpointer user_data);
void gnc_customer_window_ok_cb (GtkWidget *widget, gpointer data);
void gnc_customer_window_cancel_cb (GtkWidget *widget, gpointer data);
@@ -65,591 +65,609 @@
typedef enum
{
- NEW_CUSTOMER,
- EDIT_CUSTOMER
+ NEW_CUSTOMER,
+ EDIT_CUSTOMER
} CustomerDialogType;
-struct _customer_select_window {
- QofBook * book;
- QueryNew * q;
+struct _customer_select_window
+{
+ QofBook * book;
+ QueryNew * q;
};
-struct _customer_window {
- GtkWidget * dialog;
+struct _customer_window
+{
+ GtkWidget * dialog;
- GtkWidget * id_entry;
- GtkWidget * company_entry;
+ GtkWidget * id_entry;
+ GtkWidget * company_entry;
- GtkWidget * name_entry;
- GtkWidget * addr1_entry;
- GtkWidget * addr2_entry;
- GtkWidget * addr3_entry;
- GtkWidget * addr4_entry;
- GtkWidget * phone_entry;
- GtkWidget * fax_entry;
- GtkWidget * email_entry;
+ GtkWidget * name_entry;
+ GtkWidget * addr1_entry;
+ GtkWidget * addr2_entry;
+ GtkWidget * addr3_entry;
+ GtkWidget * addr4_entry;
+ GtkWidget * phone_entry;
+ GtkWidget * fax_entry;
+ GtkWidget * email_entry;
- GtkWidget * shipname_entry;
- GtkWidget * shipaddr1_entry;
- GtkWidget * shipaddr2_entry;
- GtkWidget * shipaddr3_entry;
- GtkWidget * shipaddr4_entry;
- GtkWidget * shipphone_entry;
- GtkWidget * shipfax_entry;
- GtkWidget * shipemail_entry;
+ GtkWidget * shipname_entry;
+ GtkWidget * shipaddr1_entry;
+ GtkWidget * shipaddr2_entry;
+ GtkWidget * shipaddr3_entry;
+ GtkWidget * shipaddr4_entry;
+ GtkWidget * shipphone_entry;
+ GtkWidget * shipfax_entry;
+ GtkWidget * shipemail_entry;
- GtkWidget * currency_edit;
- GtkWidget * terms_menu;
- GtkWidget * discount_amount;
- GtkWidget * credit_amount;
+ GtkWidget * currency_edit;
+ GtkWidget * terms_menu;
+ GtkWidget * discount_amount;
+ GtkWidget * credit_amount;
- GtkWidget * active_check;
- GtkWidget * taxincluded_menu;
- GtkWidget * notes_text;
+ GtkWidget * active_check;
+ GtkWidget * taxincluded_menu;
+ GtkWidget * notes_text;
- GtkWidget * taxtable_check;
- GtkWidget * taxtable_menu;
+ GtkWidget * taxtable_check;
+ GtkWidget * taxtable_menu;
- GncTaxIncluded taxincluded;
- GncBillTerm * terms;
- CustomerDialogType dialog_type;
- GUID customer_guid;
- gint component_id;
- QofBook * book;
- GncCustomer * created_customer;
+ GncTaxIncluded taxincluded;
+ GncBillTerm * terms;
+ CustomerDialogType dialog_type;
+ GUID customer_guid;
+ gint component_id;
+ QofBook * book;
+ GncCustomer * created_customer;
- GncTaxTable * taxtable;
+ GncTaxTable * taxtable;
};
void
gnc_customer_taxtable_check_cb (GtkToggleButton *togglebutton,
- gpointer user_data)
+ gpointer user_data)
{
- CustomerWindow *cw = user_data;
+ CustomerWindow *cw = user_data;
- if (gtk_toggle_button_get_active (togglebutton))
- gtk_widget_set_sensitive (cw->taxtable_menu, TRUE);
- else
- gtk_widget_set_sensitive (cw->taxtable_menu, FALSE);
+ if (gtk_toggle_button_get_active (togglebutton))
+ gtk_widget_set_sensitive (cw->taxtable_menu, TRUE);
+ else
+ gtk_widget_set_sensitive (cw->taxtable_menu, FALSE);
}
static GncCustomer *
cw_get_customer (CustomerWindow *cw)
{
- if (!cw)
- return NULL;
+ if (!cw)
+ return NULL;
- return gncCustomerLookup (cw->book, &cw->customer_guid);
+ return gncCustomerLookup (cw->book, &cw->customer_guid);
}
static void gnc_ui_to_customer (CustomerWindow *cw, GncCustomer *cust)
{
- GtkTextBuffer* text_buffer;
- GtkTextIter start, end;
- gchar *text;
- GncAddress *addr, *shipaddr;
+ GtkTextBuffer* text_buffer;
+ GtkTextIter start, end;
+ gchar *text;
+ GncAddress *addr, *shipaddr;
- addr = gncCustomerGetAddr (cust);
- shipaddr = gncCustomerGetShipAddr (cust);
+ addr = gncCustomerGetAddr (cust);
+ shipaddr = gncCustomerGetShipAddr (cust);
- gnc_suspend_gui_refresh ();
+ gnc_suspend_gui_refresh ();
- gncCustomerBeginEdit (cust);
+ gncCustomerBeginEdit (cust);
- gncCustomerSetID (cust, gtk_editable_get_chars
- (GTK_EDITABLE (cw->id_entry), 0, -1));
- gncCustomerSetName (cust, gtk_editable_get_chars
- (GTK_EDITABLE (cw->company_entry), 0, -1));
+ gncCustomerSetID (cust, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->id_entry), 0, -1));
+ gncCustomerSetName (cust, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->company_entry), 0, -1));
- gncAddressSetName (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->name_entry), 0, -1));
- gncAddressSetAddr1 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->addr1_entry), 0, -1));
- gncAddressSetAddr2 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->addr2_entry), 0, -1));
- gncAddressSetAddr3 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->addr3_entry), 0, -1));
- gncAddressSetAddr4 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->addr4_entry), 0, -1));
- gncAddressSetPhone (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->phone_entry), 0, -1));
- gncAddressSetFax (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->fax_entry), 0, -1));
- gncAddressSetEmail (addr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->email_entry), 0, -1));
+ gncAddressSetName (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->name_entry), 0, -1));
+ gncAddressSetAddr1 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->addr1_entry), 0, -1));
+ gncAddressSetAddr2 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->addr2_entry), 0, -1));
+ gncAddressSetAddr3 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->addr3_entry), 0, -1));
+ gncAddressSetAddr4 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->addr4_entry), 0, -1));
+ gncAddressSetPhone (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->phone_entry), 0, -1));
+ gncAddressSetFax (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->fax_entry), 0, -1));
+ gncAddressSetEmail (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->email_entry), 0, -1));
- gncAddressSetName (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipname_entry), 0, -1));
- gncAddressSetAddr1 (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipaddr1_entry), 0, -1));
- gncAddressSetAddr2 (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipaddr2_entry), 0, -1));
- gncAddressSetAddr3 (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipaddr3_entry), 0, -1));
- gncAddressSetAddr4 (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipaddr4_entry), 0, -1));
- gncAddressSetPhone (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipphone_entry), 0, -1));
- gncAddressSetFax (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipfax_entry), 0, -1));
- gncAddressSetEmail (shipaddr, gtk_editable_get_chars
- (GTK_EDITABLE (cw->shipemail_entry), 0, -1));
+ gncAddressSetName (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipname_entry), 0, -1));
+ gncAddressSetAddr1 (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipaddr1_entry), 0, -1));
+ gncAddressSetAddr2 (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipaddr2_entry), 0, -1));
+ gncAddressSetAddr3 (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipaddr3_entry), 0, -1));
+ gncAddressSetAddr4 (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipaddr4_entry), 0, -1));
+ gncAddressSetPhone (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipphone_entry), 0, -1));
+ gncAddressSetFax (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipfax_entry), 0, -1));
+ gncAddressSetEmail (shipaddr, gtk_editable_get_chars
+ (GTK_EDITABLE (cw->shipemail_entry), 0, -1));
- gncCustomerSetActive (cust, gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (cw->active_check)));
- gncCustomerSetTaxIncluded (cust, cw->taxincluded);
+ gncCustomerSetActive (cust, gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (cw->active_check)));
+ gncCustomerSetTaxIncluded (cust, cw->taxincluded);
- text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text));
- gtk_text_buffer_get_bounds (text_buffer, &start, &end);
- text = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE);
- gncCustomerSetNotes (cust, text);
+ text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text));
+ gtk_text_buffer_get_bounds (text_buffer, &start, &end);
+ text = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE);
+ gncCustomerSetNotes (cust, text);
- /* Parse and set the currency, terms, discount, and credit amounts */
- gncCustomerSetCurrency (cust,
- gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT
- (cw->currency_edit)));
- gncCustomerSetTerms (cust, cw->terms);
- gncCustomerSetDiscount (cust, gnc_amount_edit_get_amount
- (GNC_AMOUNT_EDIT (cw->discount_amount)));
- gncCustomerSetCredit (cust, gnc_amount_edit_get_amount
- (GNC_AMOUNT_EDIT (cw->credit_amount)));
+ /* Parse and set the currency, terms, discount, and credit amounts */
+ gncCustomerSetCurrency (cust,
+ gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT
+ (cw->currency_edit)));
+ gncCustomerSetTerms (cust, cw->terms);
+ gncCustomerSetDiscount (cust, gnc_amount_edit_get_amount
+ (GNC_AMOUNT_EDIT (cw->discount_amount)));
+ gncCustomerSetCredit (cust, gnc_amount_edit_get_amount
+ (GNC_AMOUNT_EDIT (cw->credit_amount)));
- gncCustomerSetTaxTableOverride
+ gncCustomerSetTaxTableOverride
(cust, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cw->taxtable_check)));
- gncCustomerSetTaxTable (cust, cw->taxtable);
+ gncCustomerSetTaxTable (cust, cw->taxtable);
- gncCustomerCommitEdit (cust);
- gnc_resume_gui_refresh ();
+ gncCustomerCommitEdit (cust);
+ gnc_resume_gui_refresh ();
}
static gboolean check_edit_amount (GtkWidget *dialog, GtkWidget *amount,
- gnc_numeric *min, gnc_numeric *max,
- const char * error_message)
+ gnc_numeric *min, gnc_numeric *max,
+ const char * error_message)
{
- if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount))) {
- if (error_message)
- gnc_error_dialog (dialog, "%s", error_message);
- return TRUE;
- }
- /* We've got a valid-looking number; check mix/max */
- if (min || max) {
- gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount));
- if ((min && gnc_numeric_compare (*min, val) > 0) ||
- (max && gnc_numeric_compare (val, *max) > 0)) {
- if (error_message)
- gnc_error_dialog (dialog, "%s", error_message);
- return TRUE;
+ if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount)))
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, "%s", error_message);
+ return TRUE;
}
- }
- return FALSE;
+ /* We've got a valid-looking number; check mix/max */
+ if (min || max)
+ {
+ gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount));
+ if ((min && gnc_numeric_compare (*min, val) > 0) ||
+ (max && gnc_numeric_compare (val, *max) > 0))
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, "%s", error_message);
+ return TRUE;
+ }
+ }
+ return FALSE;
}
-static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry,
- const char * error_message)
+static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry,
+ const char * error_message)
{
- const char *res = gtk_entry_get_text (GTK_ENTRY (entry));
- if (safe_strcmp (res, "") == 0) {
- if (error_message)
- gnc_error_dialog (dialog, "%s", error_message);
- return TRUE;
- }
- return FALSE;
+ const char *res = gtk_entry_get_text (GTK_ENTRY (entry));
+ if (safe_strcmp (res, "") == 0)
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, "%s", error_message);
+ return TRUE;
+ }
+ return FALSE;
}
void
gnc_customer_window_ok_cb (GtkWidget *widget, gpointer data)
{
- CustomerWindow *cw = data;
- gnc_numeric min, max;
- gchar *string;
+ CustomerWindow *cw = data;
+ gnc_numeric min, max;
+ gchar *string;
- /* Check for valid company name */
- if (check_entry_nonempty (cw->dialog, cw->company_entry,
- _("You must enter a company name. "
- "If this customer is an individual (and not a company) "
- "you should set the \"company name\" and \"contact name\" "
- "the same.")))
- return;
+ /* Check for valid company name */
+ if (check_entry_nonempty (cw->dialog, cw->company_entry,
+ _("You must enter a company name. "
+ "If this customer is an individual (and not a company) "
+ "you should set the \"company name\" and \"contact name\" "
+ "the same.")))
+ return;
- /* Make sure we have an address */
- if (check_entry_nonempty (cw->dialog, cw->addr1_entry, NULL) &&
- check_entry_nonempty (cw->dialog, cw->addr2_entry, NULL) &&
- check_entry_nonempty (cw->dialog, cw->addr3_entry, NULL) &&
- check_entry_nonempty (cw->dialog, cw->addr4_entry, NULL)) {
- const char *msg = _("You must enter a billing address.");
- gnc_error_dialog (cw->dialog, "%s", msg);
- return;
- }
+ /* Make sure we have an address */
+ if (check_entry_nonempty (cw->dialog, cw->addr1_entry, NULL) &&
+ check_entry_nonempty (cw->dialog, cw->addr2_entry, NULL) &&
+ check_entry_nonempty (cw->dialog, cw->addr3_entry, NULL) &&
+ check_entry_nonempty (cw->dialog, cw->addr4_entry, NULL))
+ {
+ const char *msg = _("You must enter a billing address.");
+ gnc_error_dialog (cw->dialog, "%s", msg);
+ return;
+ }
- /* Verify terms, discount, and credit are valid (or empty) */
- min = gnc_numeric_zero ();
- max = gnc_numeric_create (100, 1);
+ /* Verify terms, discount, and credit are valid (or empty) */
+ min = gnc_numeric_zero ();
+ max = gnc_numeric_create (100, 1);
- if (check_edit_amount (cw->dialog, cw->discount_amount, &min, &max,
- _("Discount percentage must be between 0-100 "
- "or you must leave it blank.")))
- return;
+ if (check_edit_amount (cw->dialog, cw->discount_amount, &min, &max,
+ _("Discount percentage must be between 0-100 "
+ "or you must leave it blank.")))
+ return;
- if (check_edit_amount (cw->dialog, cw->credit_amount, &min, NULL,
- _("Credit must be a positive amount or "
- "you must leave it blank.")))
- return;
+ if (check_edit_amount (cw->dialog, cw->credit_amount, &min, NULL,
+ _("Credit must be a positive amount or "
+ "you must leave it blank.")))
+ return;
- /* Set the customer id if one has not been chosen */
- if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (cw->id_entry)), "") == 0) {
- string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
- gncCustomerNextID (cw->book));
- gtk_entry_set_text (GTK_ENTRY (cw->id_entry), string);
- g_free(string);
- }
+ /* Set the customer id if one has not been chosen */
+ if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (cw->id_entry)), "") == 0)
+ {
+ string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
+ gncCustomerNextID (cw->book));
+ gtk_entry_set_text (GTK_ENTRY (cw->id_entry), string);
+ g_free(string);
+ }
- /* Now save it off */
- {
- GncCustomer *customer = cw_get_customer (cw);
- if (customer) {
- gnc_ui_to_customer (cw, customer);
+ /* Now save it off */
+ {
+ GncCustomer *customer = cw_get_customer (cw);
+ if (customer)
+ {
+ gnc_ui_to_customer (cw, customer);
+ }
+ cw->created_customer = customer;
+ cw->customer_guid = *xaccGUIDNULL ();
}
- cw->created_customer = customer;
- cw->customer_guid = *xaccGUIDNULL ();
- }
- gnc_close_gui_component (cw->component_id);
+ gnc_close_gui_component (cw->component_id);
}
void
gnc_customer_window_cancel_cb (GtkWidget *widget, gpointer data)
{
- CustomerWindow *cw = data;
+ CustomerWindow *cw = data;
- gnc_close_gui_component (cw->component_id);
+ gnc_close_gui_component (cw->component_id);
}
void
gnc_customer_window_help_cb (GtkWidget *widget, gpointer data)
{
- gnc_gnome_help(HF_HELP, HL_USAGE);
+ gnc_gnome_help(HF_HELP, HL_USAGE);
}
void
gnc_customer_window_destroy_cb (GtkWidget *widget, gpointer data)
{
- CustomerWindow *cw = data;
- GncCustomer *customer = cw_get_customer (cw);
+ CustomerWindow *cw = data;
+ GncCustomer *customer = cw_get_customer (cw);
- gnc_suspend_gui_refresh ();
+ gnc_suspend_gui_refresh ();
- if (cw->dialog_type == NEW_CUSTOMER && customer != NULL) {
- gncCustomerBeginEdit (customer);
- gncCustomerDestroy (customer);
- cw->customer_guid = *xaccGUIDNULL ();
- }
+ if (cw->dialog_type == NEW_CUSTOMER && customer != NULL)
+ {
+ gncCustomerBeginEdit (customer);
+ gncCustomerDestroy (customer);
+ cw->customer_guid = *xaccGUIDNULL ();
+ }
- gnc_unregister_gui_component (cw->component_id);
- gnc_resume_gui_refresh ();
+ gnc_unregister_gui_component (cw->component_id);
+ gnc_resume_gui_refresh ();
- g_free (cw);
+ g_free (cw);
}
void
gnc_customer_name_changed_cb (GtkWidget *widget, gpointer data)
{
- CustomerWindow *cw = data;
- char *fullname, *title;
- const char *id, *name;
+ CustomerWindow *cw = data;
+ char *fullname, *title;
+ const char *id, *name;
- if (!cw)
- return;
+ if (!cw)
+ return;
- name = gtk_entry_get_text (GTK_ENTRY (cw->company_entry));
- if (!name || *name == '\0')
- name = _("<No name>");
+ name = gtk_entry_get_text (GTK_ENTRY (cw->company_entry));
+ if (!name || *name == '\0')
+ name = _("<No name>");
- id = gtk_entry_get_text (GTK_ENTRY (cw->id_entry));
+ id = gtk_entry_get_text (GTK_ENTRY (cw->id_entry));
- fullname = g_strconcat (name, " (", id, ")", (char *)NULL);
+ fullname = g_strconcat (name, " (", id, ")", (char *)NULL);
- if (cw->dialog_type == EDIT_CUSTOMER)
- title = g_strconcat (_("Edit Customer"), " - ", fullname, (char *)NULL);
- else
- title = g_strconcat (_("New Customer"), " - ", fullname, (char *)NULL);
+ if (cw->dialog_type == EDIT_CUSTOMER)
+ title = g_strconcat (_("Edit Customer"), " - ", fullname, (char *)NULL);
+ else
+ title = g_strconcat (_("New Customer"), " - ", fullname, (char *)NULL);
- gtk_window_set_title (GTK_WINDOW (cw->dialog), title);
+ gtk_window_set_title (GTK_WINDOW (cw->dialog), title);
- g_free (fullname);
- g_free (title);
+ g_free (fullname);
+ g_free (title);
}
static void
gnc_customer_window_close_handler (gpointer user_data)
{
- CustomerWindow *cw = user_data;
+ CustomerWindow *cw = user_data;
- gtk_widget_destroy (cw->dialog);
- // cw has already been freed by this point.
- // cw->dialog = NULL;
+ gtk_widget_destroy (cw->dialog);
+ // cw has already been freed by this point.
+ // cw->dialog = NULL;
}
static void
gnc_customer_window_refresh_handler (GHashTable *changes, gpointer user_data)
{
- CustomerWindow *cw = user_data;
- const EventInfo *info;
- GncCustomer *customer = cw_get_customer (cw);
+ CustomerWindow *cw = user_data;
+ const EventInfo *info;
+ GncCustomer *customer = cw_get_customer (cw);
- /* If there isn't a customer behind us, close down */
- if (!customer) {
- gnc_close_gui_component (cw->component_id);
- return;
- }
+ /* If there isn't a customer behind us, close down */
+ if (!customer)
+ {
+ gnc_close_gui_component (cw->component_id);
+ return;
+ }
- /* Next, close if this is a destroy event */
- if (changes) {
- info = gnc_gui_get_entity_events (changes, &cw->customer_guid);
- if (info && (info->event_mask & QOF_EVENT_DESTROY)) {
- gnc_close_gui_component (cw->component_id);
- return;
+ /* Next, close if this is a destroy event */
+ if (changes)
+ {
+ info = gnc_gui_get_entity_events (changes, &cw->customer_guid);
+ if (info && (info->event_mask & QOF_EVENT_DESTROY))
+ {
+ gnc_close_gui_component (cw->component_id);
+ return;
+ }
}
- }
}
static gboolean
find_handler (gpointer find_data, gpointer user_data)
{
- const GUID *customer_guid = find_data;
- CustomerWindow *cw = user_data;
+ const GUID *customer_guid = find_data;
+ CustomerWindow *cw = user_data;
- return(cw && guid_equal(&cw->customer_guid, customer_guid));
+ return(cw && guid_equal(&cw->customer_guid, customer_guid));
}
static CustomerWindow *
gnc_customer_new_window (QofBook *bookp, GncCustomer *cust)
{
- CustomerWindow *cw;
- GladeXML *xml;
- GtkWidget *hbox, *edit;
- gnc_commodity *currency;
- GNCPrintAmountInfo print_info;
-
- /*
- * Find an existing window for this customer. If found, bring it to
- * the front.
- */
- if (cust) {
- GUID customer_guid;
+ CustomerWindow *cw;
+ GladeXML *xml;
+ GtkWidget *hbox, *edit;
+ gnc_commodity *currency;
+ GNCPrintAmountInfo print_info;
- customer_guid = *gncCustomerGetGUID(cust);
- cw = gnc_find_first_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
- find_handler, &customer_guid);
- if (cw) {
- gtk_window_present (GTK_WINDOW(cw->dialog));
- return(cw);
+ /*
+ * Find an existing window for this customer. If found, bring it to
+ * the front.
+ */
+ if (cust)
+ {
+ GUID customer_guid;
+
+ customer_guid = *gncCustomerGetGUID(cust);
+ cw = gnc_find_first_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
+ find_handler, &customer_guid);
+ if (cw)
+ {
+ gtk_window_present (GTK_WINDOW(cw->dialog));
+ return(cw);
+ }
}
- }
-
- /* Find the default currency */
- if (cust)
- currency = gncCustomerGetCurrency (cust);
- else
- currency = gnc_default_currency ();
- /*
- * No existing customer window found. Build a new one.
- */
- cw = g_new0 (CustomerWindow, 1);
+ /* Find the default currency */
+ if (cust)
+ currency = gncCustomerGetCurrency (cust);
+ else
+ currency = gnc_default_currency ();
- cw->book = bookp;
+ /*
+ * No existing customer window found. Build a new one.
+ */
+ cw = g_new0 (CustomerWindow, 1);
- /* Find the dialog */
- xml = gnc_glade_xml_new ("customer.glade", "Customer Dialog");
- cw->dialog = glade_xml_get_widget (xml, "Customer Dialog");
+ cw->book = bookp;
- g_object_set_data (G_OBJECT (cw->dialog), "dialog_info", cw);
+ /* Find the dialog */
+ xml = gnc_glade_xml_new ("customer.glade", "Customer Dialog");
+ cw->dialog = glade_xml_get_widget (xml, "Customer Dialog");
- /* Get entry points */
- cw->id_entry = glade_xml_get_widget (xml, "id_entry");
- cw->company_entry = glade_xml_get_widget (xml, "company_entry");
+ g_object_set_data (G_OBJECT (cw->dialog), "dialog_info", cw);
- cw->name_entry = glade_xml_get_widget (xml, "name_entry");
- cw->addr1_entry = glade_xml_get_widget (xml, "addr1_entry");
- cw->addr2_entry = glade_xml_get_widget (xml, "addr2_entry");
- cw->addr3_entry = glade_xml_get_widget (xml, "addr3_entry");
- cw->addr4_entry = glade_xml_get_widget (xml, "addr4_entry");
- cw->phone_entry = glade_xml_get_widget (xml, "phone_entry");
- cw->fax_entry = glade_xml_get_widget (xml, "fax_entry");
- cw->email_entry = glade_xml_get_widget (xml, "email_entry");
+ /* Get entry points */
+ cw->id_entry = glade_xml_get_widget (xml, "id_entry");
+ cw->company_entry = glade_xml_get_widget (xml, "company_entry");
- cw->shipname_entry = glade_xml_get_widget (xml, "shipname_entry");
- cw->shipaddr1_entry = glade_xml_get_widget (xml, "shipaddr1_entry");
- cw->shipaddr2_entry = glade_xml_get_widget (xml, "shipaddr2_entry");
- cw->shipaddr3_entry = glade_xml_get_widget (xml, "shipaddr3_entry");
- cw->shipaddr4_entry = glade_xml_get_widget (xml, "shipaddr4_entry");
- cw->shipphone_entry = glade_xml_get_widget (xml, "shipphone_entry");
- cw->shipfax_entry = glade_xml_get_widget (xml, "shipfax_entry");
- cw->shipemail_entry = glade_xml_get_widget (xml, "shipemail_entry");
+ cw->name_entry = glade_xml_get_widget (xml, "name_entry");
+ cw->addr1_entry = glade_xml_get_widget (xml, "addr1_entry");
+ cw->addr2_entry = glade_xml_get_widget (xml, "addr2_entry");
+ cw->addr3_entry = glade_xml_get_widget (xml, "addr3_entry");
+ cw->addr4_entry = glade_xml_get_widget (xml, "addr4_entry");
+ cw->phone_entry = glade_xml_get_widget (xml, "phone_entry");
+ cw->fax_entry = glade_xml_get_widget (xml, "fax_entry");
+ cw->email_entry = glade_xml_get_widget (xml, "email_entry");
- cw->active_check = glade_xml_get_widget (xml, "active_check");
- cw->taxincluded_menu = glade_xml_get_widget (xml, "tax_included_menu");
- cw->notes_text = glade_xml_get_widget (xml, "notes_text");
+ cw->shipname_entry = glade_xml_get_widget (xml, "shipname_entry");
+ cw->shipaddr1_entry = glade_xml_get_widget (xml, "shipaddr1_entry");
+ cw->shipaddr2_entry = glade_xml_get_widget (xml, "shipaddr2_entry");
+ cw->shipaddr3_entry = glade_xml_get_widget (xml, "shipaddr3_entry");
+ cw->shipaddr4_entry = glade_xml_get_widget (xml, "shipaddr4_entry");
+ cw->shipphone_entry = glade_xml_get_widget (xml, "shipphone_entry");
+ cw->shipfax_entry = glade_xml_get_widget (xml, "shipfax_entry");
+ cw->shipemail_entry = glade_xml_get_widget (xml, "shipemail_entry");
- cw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
+ cw->active_check = glade_xml_get_widget (xml, "active_check");
+ cw->taxincluded_menu = glade_xml_get_widget (xml, "tax_included_menu");
+ cw->notes_text = glade_xml_get_widget (xml, "notes_text");
- cw->taxtable_check = glade_xml_get_widget (xml, "taxtable_button");
- cw->taxtable_menu = glade_xml_get_widget (xml, "taxtable_menu");
+ cw->terms_menu = glade_xml_get_widget (xml, "terms_menu");
- /* Currency */
- edit = gnc_currency_edit_new();
- gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency);
- cw->currency_edit = edit;
+ cw->taxtable_check = glade_xml_get_widget (xml, "taxtable_button");
+ cw->taxtable_menu = glade_xml_get_widget (xml, "taxtable_menu");
- hbox = glade_xml_get_widget (xml, "currency_box");
- gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
+ /* Currency */
+ edit = gnc_currency_edit_new();
+ gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency);
+ cw->currency_edit = edit;
- /* DISCOUNT: Percentage Value */
- edit = gnc_amount_edit_new();
- gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
- print_info = gnc_integral_print_info ();
- print_info.max_decimal_places = 5;
- gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
- gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000);
- cw->discount_amount = edit;
- gtk_widget_show (edit);
+ hbox = glade_xml_get_widget (xml, "currency_box");
+ gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
- hbox = glade_xml_get_widget (xml, "discount_box");
- gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
+ /* DISCOUNT: Percentage Value */
+ edit = gnc_amount_edit_new();
+ gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
+ print_info = gnc_integral_print_info ();
+ print_info.max_decimal_places = 5;
+ gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
+ gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000);
+ cw->discount_amount = edit;
+ gtk_widget_show (edit);
- /* CREDIT: Monetary Value */
- edit = gnc_amount_edit_new();
- print_info = gnc_commodity_print_info (currency, FALSE);
- gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
- gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
- gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit),
- gnc_commodity_get_fraction (currency));
- cw->credit_amount = edit;
- gtk_widget_show (edit);
+ hbox = glade_xml_get_widget (xml, "discount_box");
+ gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
- hbox = glade_xml_get_widget (xml, "credit_box");
- gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
+ /* CREDIT: Monetary Value */
+ edit = gnc_amount_edit_new();
+ print_info = gnc_commodity_print_info (currency, FALSE);
+ gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
+ gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
+ gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit),
+ gnc_commodity_get_fraction (currency));
+ cw->credit_amount = edit;
+ gtk_widget_show (edit);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- cw);
+ hbox = glade_xml_get_widget (xml, "credit_box");
+ gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
- /* Setup initial values */
- if (cust != NULL) {
- GtkTextBuffer* text_buffer;
- GncAddress *addr, *shipaddr;
- const char *string;
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ cw);
- cw->dialog_type = EDIT_CUSTOMER;
- cw->customer_guid = *gncCustomerGetGUID (cust);
+ /* Setup initial values */
+ if (cust != NULL)
+ {
+ GtkTextBuffer* text_buffer;
+ GncAddress *addr, *shipaddr;
+ const char *string;
- addr = gncCustomerGetAddr (cust);
- shipaddr = gncCustomerGetShipAddr (cust);
+ cw->dialog_type = EDIT_CUSTOMER;
+ cw->customer_guid = *gncCustomerGetGUID (cust);
- gtk_entry_set_text (GTK_ENTRY (cw->id_entry), gncCustomerGetID (cust));
- gtk_entry_set_text (GTK_ENTRY (cw->company_entry), gncCustomerGetName (cust));
+ addr = gncCustomerGetAddr (cust);
+ shipaddr = gncCustomerGetShipAddr (cust);
- /* Setup Address */
- gtk_entry_set_text (GTK_ENTRY (cw->name_entry), gncAddressGetName (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->addr1_entry), gncAddressGetAddr1 (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->addr2_entry), gncAddressGetAddr2 (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->addr3_entry), gncAddressGetAddr3 (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->addr4_entry), gncAddressGetAddr4 (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->phone_entry), gncAddressGetPhone (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->fax_entry), gncAddressGetFax (addr));
- gtk_entry_set_text (GTK_ENTRY (cw->email_entry), gncAddressGetEmail (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->id_entry), gncCustomerGetID (cust));
+ gtk_entry_set_text (GTK_ENTRY (cw->company_entry), gncCustomerGetName (cust));
- /* Setup Ship-to Address */
- gtk_entry_set_text (GTK_ENTRY (cw->shipname_entry), gncAddressGetName (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipaddr1_entry), gncAddressGetAddr1 (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipaddr2_entry), gncAddressGetAddr2 (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipaddr3_entry), gncAddressGetAddr3 (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipaddr4_entry), gncAddressGetAddr4 (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipphone_entry), gncAddressGetPhone (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipfax_entry), gncAddressGetFax (shipaddr));
- gtk_entry_set_text (GTK_ENTRY (cw->shipemail_entry), gncAddressGetEmail (shipaddr));
+ /* Setup Address */
+ gtk_entry_set_text (GTK_ENTRY (cw->name_entry), gncAddressGetName (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->addr1_entry), gncAddressGetAddr1 (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->addr2_entry), gncAddressGetAddr2 (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->addr3_entry), gncAddressGetAddr3 (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->addr4_entry), gncAddressGetAddr4 (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->phone_entry), gncAddressGetPhone (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->fax_entry), gncAddressGetFax (addr));
+ gtk_entry_set_text (GTK_ENTRY (cw->email_entry), gncAddressGetEmail (addr));
- /* Set toggle buttons */
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->active_check),
- gncCustomerGetActive (cust));
+ /* Setup Ship-to Address */
+ gtk_entry_set_text (GTK_ENTRY (cw->shipname_entry), gncAddressGetName (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipaddr1_entry), gncAddressGetAddr1 (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipaddr2_entry), gncAddressGetAddr2 (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipaddr3_entry), gncAddressGetAddr3 (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipaddr4_entry), gncAddressGetAddr4 (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipphone_entry), gncAddressGetPhone (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipfax_entry), gncAddressGetFax (shipaddr));
+ gtk_entry_set_text (GTK_ENTRY (cw->shipemail_entry), gncAddressGetEmail (shipaddr));
- string = gncCustomerGetNotes (cust);
- text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text));
- gtk_text_buffer_set_text (text_buffer, string, -1);
+ /* Set toggle buttons */
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->active_check),
+ gncCustomerGetActive (cust));
- cw->component_id =
- gnc_register_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
- gnc_customer_window_refresh_handler,
- gnc_customer_window_close_handler,
- cw);
- cw->terms = gncCustomerGetTerms (cust);
+ string = gncCustomerGetNotes (cust);
+ text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text));
+ gtk_text_buffer_set_text (text_buffer, string, -1);
- } else {
- cust = gncCustomerCreate (bookp);
- cw->customer_guid = *gncCustomerGetGUID (cust);
+ cw->component_id =
+ gnc_register_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
+ gnc_customer_window_refresh_handler,
+ gnc_customer_window_close_handler,
+ cw);
+ cw->terms = gncCustomerGetTerms (cust);
- cw->dialog_type = NEW_CUSTOMER;
- cw->component_id =
- gnc_register_gui_component (DIALOG_NEW_CUSTOMER_CM_CLASS,
- gnc_customer_window_refresh_handler,
- gnc_customer_window_close_handler,
- cw);
+ }
+ else
+ {
+ cust = gncCustomerCreate (bookp);
+ cw->customer_guid = *gncCustomerGetGUID (cust);
- /* XXX: get the global-default terms */
- cw->terms = NULL;
- }
+ cw->dialog_type = NEW_CUSTOMER;
+ cw->component_id =
+ gnc_register_gui_component (DIALOG_NEW_CUSTOMER_CM_CLASS,
+ gnc_customer_window_refresh_handler,
+ gnc_customer_window_close_handler,
+ cw);
- /* I know that cust exists here -- either passed in or just created */
+ /* XXX: get the global-default terms */
+ cw->terms = NULL;
+ }
- cw->taxincluded = gncCustomerGetTaxIncluded (cust);
- gnc_ui_taxincluded_optionmenu (cw->taxincluded_menu, &cw->taxincluded);
- gnc_ui_billterms_optionmenu (cw->terms_menu, bookp, TRUE, &cw->terms);
+ /* I know that cust exists here -- either passed in or just created */
- cw->taxtable = gncCustomerGetTaxTable (cust);
- gnc_ui_taxtables_optionmenu (cw->taxtable_menu, bookp, TRUE, &cw->taxtable);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxtable_check),
- gncCustomerGetTaxTableOverride (cust));
- gnc_customer_taxtable_check_cb (GTK_TOGGLE_BUTTON (cw->taxtable_check), cw);
+ cw->taxincluded = gncCustomerGetTaxIncluded (cust);
+ gnc_ui_taxincluded_optionmenu (cw->taxincluded_menu, &cw->taxincluded);
+ gnc_ui_billterms_optionmenu (cw->terms_menu, bookp, TRUE, &cw->terms);
- /* Set the Discount, and Credit amounts */
- gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount),
- gncCustomerGetDiscount (cust));
- gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->credit_amount),
- gncCustomerGetCredit (cust));
+ cw->taxtable = gncCustomerGetTaxTable (cust);
+ gnc_ui_taxtables_optionmenu (cw->taxtable_menu, bookp, TRUE, &cw->taxtable);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxtable_check),
+ gncCustomerGetTaxTableOverride (cust));
+ gnc_customer_taxtable_check_cb (GTK_TOGGLE_BUTTON (cw->taxtable_check), cw);
- gnc_gui_component_watch_entity_type (cw->component_id,
- GNC_CUSTOMER_MODULE_NAME,
- QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
+ /* Set the Discount, and Credit amounts */
+ gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount),
+ gncCustomerGetDiscount (cust));
+ gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->credit_amount),
+ gncCustomerGetCredit (cust));
- gtk_widget_show_all (cw->dialog);
+ gnc_gui_component_watch_entity_type (cw->component_id,
+ GNC_CUSTOMER_MODULE_NAME,
+ QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
- return cw;
+ gtk_widget_show_all (cw->dialog);
+
+ return cw;
}
CustomerWindow *
gnc_ui_customer_edit (GncCustomer *cust)
{
- CustomerWindow *cw;
+ CustomerWindow *cw;
- if (!cust) return NULL;
+ if (!cust) return NULL;
- cw = gnc_customer_new_window (gncCustomerGetBook(cust), cust);
+ cw = gnc_customer_new_window (gncCustomerGetBook(cust), cust);
- return cw;
+ return cw;
}
CustomerWindow *
gnc_ui_customer_new (QofBook *bookp)
{
- CustomerWindow *cw;
+ CustomerWindow *cw;
- /* Make sure required options exist */
- if (!bookp) return NULL;
+ /* Make sure required options exist */
+ if (!bookp) return NULL;
- cw = gnc_customer_new_window (bookp, NULL);
+ cw = gnc_customer_new_window (bookp, NULL);
- return cw;
+ return cw;
}
/* Functions for customer selection widgets */
@@ -657,197 +675,201 @@
static void
invoice_customer_cb (gpointer *cust_p, gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
- GncOwner owner;
- GncCustomer *cust;
+ struct _customer_select_window *sw = user_data;
+ GncOwner owner;
+ GncCustomer *cust;
- g_return_if_fail (cust_p && user_data);
+ g_return_if_fail (cust_p && user_data);
- cust = *cust_p;
+ cust = *cust_p;
- if (!cust)
+ if (!cust)
+ return;
+
+ gncOwnerInitCustomer (&owner, cust);
+ gnc_invoice_search (NULL, &owner, sw->book);
return;
-
- gncOwnerInitCustomer (&owner, cust);
- gnc_invoice_search (NULL, &owner, sw->book);
- return;
}
static void
order_customer_cb (gpointer *cust_p, gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
- GncOwner owner;
- GncCustomer *cust;
+ struct _customer_select_window *sw = user_data;
+ GncOwner owner;
+ GncCustomer *cust;
- g_return_if_fail (cust_p && user_data);
+ g_return_if_fail (cust_p && user_data);
- cust = *cust_p;
+ cust = *cust_p;
- if (!cust)
+ if (!cust)
+ return;
+
+ gncOwnerInitCustomer (&owner, cust);
+ gnc_order_search (NULL, &owner, sw->book);
return;
-
- gncOwnerInitCustomer (&owner, cust);
- gnc_order_search (NULL, &owner, sw->book);
- return;
}
static void
jobs_customer_cb (gpointer *cust_p, gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
- GncOwner owner;
- GncCustomer *cust;
+ struct _customer_select_window *sw = user_data;
+ GncOwner owner;
+ GncCustomer *cust;
- g_return_if_fail (cust_p && user_data);
+ g_return_if_fail (cust_p && user_data);
- cust = *cust_p;
+ cust = *cust_p;
- if (!cust)
+ if (!cust)
+ return;
+
+ gncOwnerInitCustomer (&owner, cust);
+ gnc_job_search (NULL, &owner, sw->book);
return;
-
- gncOwnerInitCustomer (&owner, cust);
- gnc_job_search (NULL, &owner, sw->book);
- return;
}
static void
payment_customer_cb (gpointer *cust_p, gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
- GncOwner owner;
- GncCustomer *cust;
+ struct _customer_select_window *sw = user_data;
+ GncOwner owner;
+ GncCustomer *cust;
- g_return_if_fail (cust_p && user_data);
+ g_return_if_fail (cust_p && user_data);
- cust = *cust_p;
+ cust = *cust_p;
- if (!cust)
+ if (!cust)
+ return;
+
+ gncOwnerInitCustomer (&owner, cust);
+ gnc_ui_payment_new (&owner, sw->book);
return;
-
- gncOwnerInitCustomer (&owner, cust);
- gnc_ui_payment_new (&owner, sw->book);
- return;
}
static void
edit_customer_cb (gpointer *cust_p, gpointer user_data)
{
- GncCustomer *cust;
+ GncCustomer *cust;
- g_return_if_fail (cust_p);
- cust = *cust_p;
+ g_return_if_fail (cust_p);
+ cust = *cust_p;
- if (!cust)
- return;
+ if (!cust)
+ return;
- gnc_ui_customer_edit (cust);
+ gnc_ui_customer_edit (cust);
- return;
+ return;
}
static gpointer
new_customer_cb (gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
- CustomerWindow *cw;
-
- g_return_val_if_fail (sw, NULL);
+ struct _customer_select_window *sw = user_data;
+ CustomerWindow *cw;
- cw = gnc_ui_customer_new (sw->book);
- return cw_get_customer (cw);
+ g_return_val_if_fail (sw, NULL);
+
+ cw = gnc_ui_customer_new (sw->book);
+ return cw_get_customer (cw);
}
static void
free_userdata_cb (gpointer user_data)
{
- struct _customer_select_window *sw = user_data;
+ struct _customer_select_window *sw = user_data;
- g_return_if_fail (sw);
+ g_return_if_fail (sw);
- gncQueryDestroy (sw->q);
- g_free (sw);
+ gncQueryDestroy (sw->q);
+ g_free (sw);
}
GNCSearchWindow *
gnc_customer_search (GncCustomer *start, QofBook *book)
{
- QueryNew *q, *q2 = NULL;
- GNCIdType type = GNC_CUSTOMER_MODULE_NAME;
- struct _customer_select_window *sw;
- static GList *params = NULL;
- static GList *columns = NULL;
- static GNCSearchCallbackButton buttons[] = {
- { N_("View/Edit Customer"), edit_customer_cb},
- { N_("Customer's Jobs"), jobs_customer_cb},
- // { N_("Customer's Orders"), order_customer_cb},
- { N_("Customer's Invoices"), invoice_customer_cb},
- { N_("Process Payment"), payment_customer_cb},
- { NULL },
- };
- (void)order_customer_cb;
+ QueryNew *q, *q2 = NULL;
+ GNCIdType type = GNC_CUSTOMER_MODULE_NAME;
+ struct _customer_select_window *sw;
+ static GList *params = NULL;
+ static GList *columns = NULL;
+ static GNCSearchCallbackButton buttons[] =
+ {
+ { N_("View/Edit Customer"), edit_customer_cb},
+ { N_("Customer's Jobs"), jobs_customer_cb},
+ // { N_("Customer's Orders"), order_customer_cb},
+ { N_("Customer's Invoices"), invoice_customer_cb},
+ { N_("Process Payment"), payment_customer_cb},
+ { NULL },
+ };
+ (void)order_customer_cb;
- g_return_val_if_fail (book, NULL);
+ g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
- if (params == NULL) {
- params = gnc_search_param_prepend (params, _("Shipping Contact"), NULL, type,
- CUSTOMER_SHIPADDR, ADDRESS_NAME, NULL);
- params = gnc_search_param_prepend (params, _("Billing Contact"), NULL, type,
- CUSTOMER_ADDR, ADDRESS_NAME, NULL);
- params = gnc_search_param_prepend (params, _("Customer ID"), NULL, type,
- CUSTOMER_ID, NULL);
- params = gnc_search_param_prepend (params, _("Company Name"), NULL, type,
- CUSTOMER_NAME, NULL);
- }
+ /* Build parameter list in reverse order*/
+ if (params == NULL)
+ {
+ params = gnc_search_param_prepend (params, _("Shipping Contact"), NULL, type,
+ CUSTOMER_SHIPADDR, ADDRESS_NAME, NULL);
+ params = gnc_search_param_prepend (params, _("Billing Contact"), NULL, type,
+ CUSTOMER_ADDR, ADDRESS_NAME, NULL);
+ params = gnc_search_param_prepend (params, _("Customer ID"), NULL, type,
+ CUSTOMER_ID, NULL);
+ params = gnc_search_param_prepend (params, _("Company Name"), NULL, type,
+ CUSTOMER_NAME, NULL);
+ }
- /* Build the column list in reverse order */
- if (columns == NULL) {
- columns = gnc_search_param_prepend (columns, _("Contact"), NULL, type,
- CUSTOMER_ADDR, ADDRESS_NAME, NULL);
- columns = gnc_search_param_prepend (columns, _("Company"), NULL, type,
- CUSTOMER_NAME, NULL);
- columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type,
- CUSTOMER_ID, NULL);
- }
+ /* Build the column list in reverse order */
+ if (columns == NULL)
+ {
+ columns = gnc_search_param_prepend (columns, _("Contact"), NULL, type,
+ CUSTOMER_ADDR, ADDRESS_NAME, NULL);
+ columns = gnc_search_param_prepend (columns, _("Company"), NULL, type,
+ CUSTOMER_NAME, NULL);
+ columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type,
+ CUSTOMER_ID, NULL);
+ }
- /* Build the queries */
- q = gncQueryCreateFor (type);
- gncQuerySetBook (q, book);
+ /* Build the queries */
+ q = gncQueryCreateFor (type);
+ gncQuerySetBook (q, book);
#if 0
- if (start) {
- q2 = gncQueryCopy (q);
- gncQueryAddGUIDMatch (q2, g_slist_prepend (NULL, QUERY_PARAM_GUID),
- gncCustomerGetGUID (start), QUERY_AND);
- }
+ if (start)
+ {
+ q2 = gncQueryCopy (q);
+ gncQueryAddGUIDMatch (q2, g_slist_prepend (NULL, QUERY_PARAM_GUID),
+ gncCustomerGetGUID (start), QUERY_AND);
+ }
#endif
- /* launch select dialog and return the result */
- sw = g_new0 (struct _customer_select_window, 1);
+ /* launch select dialog and return the result */
+ sw = g_new0 (struct _customer_select_window, 1);
- sw->book = book;
- sw->q = q;
+ sw->book = book;
+ sw->q = q;
- return gnc_search_dialog_create (type, _("Find Customer"),
- params, columns, q, q2, buttons, NULL,
- new_customer_cb, sw, free_userdata_cb,
- GCONF_SECTION_SEARCH, NULL);
+ return gnc_search_dialog_create (type, _("Find Customer"),
+ params, columns, q, q2, buttons, NULL,
+ new_customer_cb, sw, free_userdata_cb,
+ GCONF_SECTION_SEARCH, NULL);
}
GNCSearchWindow *
gnc_customer_search_select (gpointer start, gpointer book)
{
- if (!book) return NULL;
+ if (!book) return NULL;
- return gnc_customer_search (start, book);
+ return gnc_customer_search (start, book);
}
GNCSearchWindow *
gnc_customer_search_edit (gpointer start, gpointer book)
{
- if (start)
- gnc_ui_customer_edit (start);
+ if (start)
+ gnc_ui_customer_edit (start);
- return NULL;
+ return NULL;
}
Modified: gnucash/trunk/src/business/business-gnome/dialog-date-close.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-date-close.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-date-close.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -37,22 +37,23 @@
#include "business-gnome-utils.h"
#include "dialog-date-close.h"
-typedef struct _dialog_date_close_window {
- GtkWidget *dialog;
- GtkWidget *date;
- GtkWidget *post_date;
- GtkWidget *acct_combo;
- GtkWidget *memo_entry;
- GtkWidget *question_check;
- GncBillTerm *terms;
- Timespec *ts, *ts2;
- GList * acct_types;
- GList * acct_commodities;
- QofBook *book;
- Account *acct;
- char **memo;
- gboolean retval;
- gboolean answer;
+typedef struct _dialog_date_close_window
+{
+ GtkWidget *dialog;
+ GtkWidget *date;
+ GtkWidget *post_date;
+ GtkWidget *acct_combo;
+ GtkWidget *memo_entry;
+ GtkWidget *question_check;
+ GncBillTerm *terms;
+ Timespec *ts, *ts2;
+ GList * acct_types;
+ GList * acct_commodities;
+ QofBook *book;
+ Account *acct;
+ char **memo;
+ gboolean retval;
+ gboolean answer;
} DialogDateClose;
void gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data);
@@ -61,369 +62,383 @@
void
gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
{
- DialogDateClose *ddc = user_data;
+ DialogDateClose *ddc = user_data;
- if (ddc->acct_combo) {
- Account *acc;
+ if (ddc->acct_combo)
+ {
+ Account *acc;
- acc = gnc_account_sel_get_account( GNC_ACCOUNT_SEL(ddc->acct_combo) );
+ acc = gnc_account_sel_get_account( GNC_ACCOUNT_SEL(ddc->acct_combo) );
- if (!acc) {
- gnc_error_dialog (ddc->dialog, "%s",
- _("No Account selected. Please try again."));
- return;
- }
+ if (!acc)
+ {
+ gnc_error_dialog (ddc->dialog, "%s",
+ _("No Account selected. Please try again."));
+ return;
+ }
- if (xaccAccountGetPlaceholder (acc)) {
- gnc_error_dialog (ddc->dialog, "%s",
- _("Placeholder account selected. Please try again."));
- return;
+ if (xaccAccountGetPlaceholder (acc))
+ {
+ gnc_error_dialog (ddc->dialog, "%s",
+ _("Placeholder account selected. Please try again."));
+ return;
+ }
+
+ ddc->acct = acc;
}
- ddc->acct = acc;
- }
+ if (ddc->post_date)
+ *(ddc->ts2) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->post_date));
- if (ddc->post_date)
- *(ddc->ts2) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->post_date));
+ if (ddc->date)
+ {
+ if (ddc->terms)
+ *(ddc->ts) = gncBillTermComputeDueDate (ddc->terms, *(ddc->ts2));
+ else
+ *(ddc->ts) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->date));
+ }
- if (ddc->date) {
- if (ddc->terms)
- *(ddc->ts) = gncBillTermComputeDueDate (ddc->terms, *(ddc->ts2));
- else
- *(ddc->ts) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->date));
- }
-
- if (ddc->memo_entry && ddc->memo)
- *(ddc->memo) = gtk_editable_get_chars (GTK_EDITABLE (ddc->memo_entry),
- 0, -1);
- if (ddc->question_check)
- ddc->answer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ddc->question_check));
- ddc->retval = TRUE;
+ if (ddc->memo_entry && ddc->memo)
+ *(ddc->memo) = gtk_editable_get_chars (GTK_EDITABLE (ddc->memo_entry),
+ 0, -1);
+ if (ddc->question_check)
+ ddc->answer = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ddc->question_check));
+ ddc->retval = TRUE;
}
static void
fill_in_acct_info (DialogDateClose *ddc, gboolean set_default_acct)
{
- GNCAccountSel *gas = GNC_ACCOUNT_SEL (ddc->acct_combo);
+ GNCAccountSel *gas = GNC_ACCOUNT_SEL (ddc->acct_combo);
- /* How do I set the book? */
- gnc_account_sel_set_acct_filters( gas, ddc->acct_types, ddc->acct_commodities );
- gnc_account_sel_set_new_account_ability( gas, TRUE );
- gnc_account_sel_set_new_account_modal( gas, TRUE );
- gnc_account_sel_set_account( gas, ddc->acct, set_default_acct );
+ /* How do I set the book? */
+ gnc_account_sel_set_acct_filters( gas, ddc->acct_types, ddc->acct_commodities );
+ gnc_account_sel_set_new_account_ability( gas, TRUE );
+ gnc_account_sel_set_new_account_modal( gas, TRUE );
+ gnc_account_sel_set_account( gas, ddc->acct, set_default_acct );
}
static void
build_date_close_window (GtkWidget *hbox, const char *message)
{
- GtkWidget *pixmap = NULL;
- GtkWidget *label;
- GtkWidget *alignment;
- char *s;
+ GtkWidget *pixmap = NULL;
+ GtkWidget *label;
+ GtkWidget *alignment;
+ char *s;
- s = gnome_program_locate_file (NULL,
- GNOME_FILE_DOMAIN_PIXMAP,
- "gnome-question.png", TRUE, NULL);
- if (s) {
- pixmap = gtk_image_new_from_file(s);
- g_free(s);
- }
+ s = gnome_program_locate_file (NULL,
+ GNOME_FILE_DOMAIN_PIXMAP,
+ "gnome-question.png", TRUE, NULL);
+ if (s)
+ {
+ pixmap = gtk_image_new_from_file(s);
+ g_free(s);
+ }
- if (pixmap) {
- gtk_box_pack_start (GTK_BOX(hbox), pixmap, FALSE, TRUE, 0);
- gtk_widget_show (pixmap);
- }
+ if (pixmap)
+ {
+ gtk_box_pack_start (GTK_BOX(hbox), pixmap, FALSE, TRUE, 0);
+ gtk_widget_show (pixmap);
+ }
- label = gtk_label_new (message);
- gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
- gtk_misc_set_padding (GTK_MISC (label), GNOME_PAD, 0);
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- gtk_widget_show (label);
+ label = gtk_label_new (message);
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+ gtk_misc_set_padding (GTK_MISC (label), GNOME_PAD, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
- /* Add some extra space on the right to balance the pixmap */
- if (pixmap) {
- alignment = gtk_alignment_new (0., 0., 0., 0.);
- gtk_widget_set_size_request (alignment, GNOME_PAD, -1);
- gtk_widget_show (alignment);
-
- gtk_box_pack_start (GTK_BOX (hbox), alignment, FALSE, FALSE, 0);
- }
+ /* Add some extra space on the right to balance the pixmap */
+ if (pixmap)
+ {
+ alignment = gtk_alignment_new (0., 0., 0., 0.);
+ gtk_widget_set_size_request (alignment, GNOME_PAD, -1);
+ gtk_widget_show (alignment);
+
+ gtk_box_pack_start (GTK_BOX (hbox), alignment, FALSE, FALSE, 0);
+ }
}
gboolean
gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
- const char *label_message,
- gboolean ok_is_default,
- /* Returned data ... */
- Timespec *ts)
+ const char *label_message,
+ gboolean ok_is_default,
+ /* Returned data ... */
+ Timespec *ts)
{
- DialogDateClose *ddc;
- GtkWidget *date_box;
- GtkWidget *hbox;
- GtkWidget *label;
- GladeXML *xml;
- gboolean retval;
+ DialogDateClose *ddc;
+ GtkWidget *date_box;
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GladeXML *xml;
+ gboolean retval;
- if (!message || !label_message || !ts)
- return FALSE;
+ if (!message || !label_message || !ts)
+ return FALSE;
- ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = ts;
+ ddc = g_new0 (DialogDateClose, 1);
+ ddc->ts = ts;
- xml = gnc_glade_xml_new ("date-close.glade", "Date Close Dialog");
- ddc->dialog = glade_xml_get_widget (xml, "Date Close Dialog");
- hbox = glade_xml_get_widget (xml, "the_hbox");
- label = glade_xml_get_widget (xml, "label");
+ xml = gnc_glade_xml_new ("date-close.glade", "Date Close Dialog");
+ ddc->dialog = glade_xml_get_widget (xml, "Date Close Dialog");
+ hbox = glade_xml_get_widget (xml, "the_hbox");
+ label = glade_xml_get_widget (xml, "label");
- date_box = glade_xml_get_widget (xml, "date_box");
- ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
- gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
+ date_box = glade_xml_get_widget (xml, "date_box");
+ ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
+ gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
- if (parent)
- gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
+ if (parent)
+ gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
- build_date_close_window (hbox, message);
+ build_date_close_window (hbox, message);
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ts);
- gtk_label_set_text (GTK_LABEL (label), label_message);
+ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ts);
+ gtk_label_set_text (GTK_LABEL (label), label_message);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- ddc);
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ ddc);
- gtk_widget_show_all (ddc->dialog);
+ gtk_widget_show_all (ddc->dialog);
- ddc->retval = FALSE;
- while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK) {
- /* If reponse is OK but flag is not set, try again */
- if (ddc->retval)
- break;
- }
+ ddc->retval = FALSE;
+ while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK)
+ {
+ /* If reponse is OK but flag is not set, try again */
+ if (ddc->retval)
+ break;
+ }
- gtk_widget_destroy(ddc->dialog);
- retval = ddc->retval;
- g_list_free (ddc->acct_types);
- g_free (ddc);
+ gtk_widget_destroy(ddc->dialog);
+ retval = ddc->retval;
+ g_list_free (ddc->acct_types);
+ g_free (ddc);
- return retval;
+ return retval;
}
static void
post_date_changed_cb (GNCDateEdit *gde, gpointer d)
{
- DialogDateClose *ddc = d;
- Timespec post_date;
- Timespec due_date;
+ DialogDateClose *ddc = d;
+ Timespec post_date;
+ Timespec due_date;
- post_date = gnc_date_edit_get_date_ts (gde);
- due_date = gncBillTermComputeDueDate (ddc->terms, post_date);
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), due_date);
+ post_date = gnc_date_edit_get_date_ts (gde);
+ due_date = gncBillTermComputeDueDate (ddc->terms, post_date);
+ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), due_date);
}
gboolean
gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
- const char *ddue_label_message,
- const char *post_label_message,
- const char *acct_label_message,
- const char *question_check_message,
- gboolean ok_is_default,
- gboolean set_default_acct,
- GList * acct_types, GList * acct_commodities,
- QofBook *book, GncBillTerm *terms,
- /* Returned Data... */
- Timespec *ddue, Timespec *post,
- char **memo, Account **acct, gboolean *answer)
+ const char *ddue_label_message,
+ const char *post_label_message,
+ const char *acct_label_message,
+ const char *question_check_message,
+ gboolean ok_is_default,
+ gboolean set_default_acct,
+ GList * acct_types, GList * acct_commodities,
+ QofBook *book, GncBillTerm *terms,
+ /* Returned Data... */
+ Timespec *ddue, Timespec *post,
+ char **memo, Account **acct, gboolean *answer)
{
- DialogDateClose *ddc;
- GtkWidget *hbox;
- GtkWidget *label;
- GtkWidget *date_box;
- GtkWidget *acct_box;
- GladeXML *xml;
- gboolean retval;
+ DialogDateClose *ddc;
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *date_box;
+ GtkWidget *acct_box;
+ GladeXML *xml;
+ gboolean retval;
- if (!message || !ddue_label_message || !post_label_message ||
- !acct_label_message || !acct_types || !book || !ddue || !post || !acct)
- return FALSE;
- if (question_check_message && !answer)
- return FALSE;
+ if (!message || !ddue_label_message || !post_label_message ||
+ !acct_label_message || !acct_types || !book || !ddue || !post || !acct)
+ return FALSE;
+ if (question_check_message && !answer)
+ return FALSE;
- ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = ddue;
- ddc->ts2 = post;
- ddc->book = book;
- ddc->acct_types = acct_types;
- ddc->acct_commodities = acct_commodities;
- ddc->acct = *acct;
- ddc->memo = memo;
- ddc->terms = terms;
+ ddc = g_new0 (DialogDateClose, 1);
+ ddc->ts = ddue;
+ ddc->ts2 = post;
+ ddc->book = book;
+ ddc->acct_types = acct_types;
+ ddc->acct_commodities = acct_commodities;
+ ddc->acct = *acct;
+ ddc->memo = memo;
+ ddc->terms = terms;
- xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
- ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
- ddc->memo_entry = glade_xml_get_widget (xml, "memo_entry");
- hbox = glade_xml_get_widget (xml, "the_hbox");
+ xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
+ ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
+ ddc->memo_entry = glade_xml_get_widget (xml, "memo_entry");
+ hbox = glade_xml_get_widget (xml, "the_hbox");
- acct_box = glade_xml_get_widget (xml, "acct_hbox");
- ddc->acct_combo = gnc_account_sel_new();
- gtk_box_pack_start (GTK_BOX(acct_box), ddc->acct_combo, TRUE, TRUE, 0);
+ acct_box = glade_xml_get_widget (xml, "acct_hbox");
+ ddc->acct_combo = gnc_account_sel_new();
+ gtk_box_pack_start (GTK_BOX(acct_box), ddc->acct_combo, TRUE, TRUE, 0);
- date_box = glade_xml_get_widget (xml, "date_box");
- ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
- gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
+ date_box = glade_xml_get_widget (xml, "date_box");
+ ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
+ gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
- date_box = glade_xml_get_widget (xml, "post_date_box");
- ddc->post_date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
- gtk_box_pack_start (GTK_BOX(date_box), ddc->post_date, TRUE, TRUE, 0);
+ date_box = glade_xml_get_widget (xml, "post_date_box");
+ ddc->post_date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
+ gtk_box_pack_start (GTK_BOX(date_box), ddc->post_date, TRUE, TRUE, 0);
- ddc->question_check = glade_xml_get_widget(xml, "question_check");
-
- if (parent)
- gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
+ ddc->question_check = glade_xml_get_widget(xml, "question_check");
- build_date_close_window (hbox, message);
+ if (parent)
+ gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
- /* Set the labels */
- label = glade_xml_get_widget (xml, "date_label");
- gtk_label_set_text (GTK_LABEL (label), ddue_label_message);
- label = glade_xml_get_widget (xml, "postdate_label");
- gtk_label_set_text (GTK_LABEL (label), post_label_message);
- label = glade_xml_get_widget (xml, "acct_label");
- gtk_label_set_text (GTK_LABEL (label), acct_label_message);
+ build_date_close_window (hbox, message);
- if (question_check_message)
- {
- gtk_label_set_text(GTK_LABEL(GTK_BIN(ddc->question_check)->child), question_check_message);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ddc->question_check), *answer);
- } else {
- gtk_widget_hide(ddc->question_check);
- gtk_widget_hide(glade_xml_get_widget(xml, "hide1"));
- }
+ /* Set the labels */
+ label = glade_xml_get_widget (xml, "date_label");
+ gtk_label_set_text (GTK_LABEL (label), ddue_label_message);
+ label = glade_xml_get_widget (xml, "postdate_label");
+ gtk_label_set_text (GTK_LABEL (label), post_label_message);
+ label = glade_xml_get_widget (xml, "acct_label");
+ gtk_label_set_text (GTK_LABEL (label), acct_label_message);
+ if (question_check_message)
+ {
+ gtk_label_set_text(GTK_LABEL(GTK_BIN(ddc->question_check)->child), question_check_message);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ddc->question_check), *answer);
+ }
+ else
+ {
+ gtk_widget_hide(ddc->question_check);
+ gtk_widget_hide(glade_xml_get_widget(xml, "hide1"));
+ }
- /* Set the post date widget */
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->post_date), *post);
- /* Deal with the terms handling of the due date */
- if (terms) {
- g_signal_connect (G_OBJECT (ddc->post_date), "date_changed",
- G_CALLBACK (post_date_changed_cb), ddc);
- gtk_widget_set_sensitive (ddc->date, FALSE);
- post_date_changed_cb (GNC_DATE_EDIT (ddc->post_date), ddc);
- } else
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ddue);
+ /* Set the post date widget */
+ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->post_date), *post);
- /* Setup the account widget */
- fill_in_acct_info (ddc, set_default_acct);
+ /* Deal with the terms handling of the due date */
+ if (terms)
+ {
+ g_signal_connect (G_OBJECT (ddc->post_date), "date_changed",
+ G_CALLBACK (post_date_changed_cb), ddc);
+ gtk_widget_set_sensitive (ddc->date, FALSE);
+ post_date_changed_cb (GNC_DATE_EDIT (ddc->post_date), ddc);
+ }
+ else
+ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ddue);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- ddc);
+ /* Setup the account widget */
+ fill_in_acct_info (ddc, set_default_acct);
- gtk_widget_show_all (ddc->dialog);
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ ddc);
- /* Set the focus on the date widget */
- gnc_date_grab_focus (GNC_DATE_EDIT (ddc->post_date));
+ gtk_widget_show_all (ddc->dialog);
- ddc->retval = FALSE;
- while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK) {
- /* If reponse is OK but flag is not set, try again */
- if (ddc->retval)
- break;
- }
+ /* Set the focus on the date widget */
+ gnc_date_grab_focus (GNC_DATE_EDIT (ddc->post_date));
- gtk_widget_destroy(ddc->dialog);
- retval = ddc->retval;
- *acct = ddc->acct;
- if (question_check_message)
- *answer = ddc->answer;
- g_free (ddc);
+ ddc->retval = FALSE;
+ while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK)
+ {
+ /* If reponse is OK but flag is not set, try again */
+ if (ddc->retval)
+ break;
+ }
- return retval;
+ gtk_widget_destroy(ddc->dialog);
+ retval = ddc->retval;
+ *acct = ddc->acct;
+ if (question_check_message)
+ *answer = ddc->answer;
+ g_free (ddc);
+
+ return retval;
}
gboolean
gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
- const char *date_label_message,
- const char *acct_label_message,
- gboolean ok_is_default,
- GList * acct_types, QofBook *book,
- /* Returned Data... */
- Timespec *date, Account **acct)
+ const char *date_label_message,
+ const char *acct_label_message,
+ gboolean ok_is_default,
+ GList * acct_types, QofBook *book,
+ /* Returned Data... */
+ Timespec *date, Account **acct)
{
- DialogDateClose *ddc;
- GtkWidget *hbox;
- GtkWidget *label;
- GtkWidget *date_box;
- GtkWidget *acct_box;
- GladeXML *xml;
- gboolean retval;
+ DialogDateClose *ddc;
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *date_box;
+ GtkWidget *acct_box;
+ GladeXML *xml;
+ gboolean retval;
- if (!message || !date_label_message || !acct_label_message ||
- !acct_types || !book || !date || !acct)
- return FALSE;
+ if (!message || !date_label_message || !acct_label_message ||
+ !acct_types || !book || !date || !acct)
+ return FALSE;
- ddc = g_new0 (DialogDateClose, 1);
- ddc->ts = date;
- ddc->book = book;
- ddc->acct_types = acct_types;
- ddc->acct = *acct;
+ ddc = g_new0 (DialogDateClose, 1);
+ ddc->ts = date;
+ ddc->book = book;
+ ddc->acct_types = acct_types;
+ ddc->acct = *acct;
- xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
- ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
- hbox = glade_xml_get_widget (xml, "the_hbox");
+ xml = gnc_glade_xml_new ("date-close.glade", "Date Account Dialog");
+ ddc->dialog = glade_xml_get_widget (xml, "Date Account Dialog");
+ hbox = glade_xml_get_widget (xml, "the_hbox");
- acct_box = glade_xml_get_widget (xml, "acct_hbox");
- ddc->acct_combo = gnc_account_sel_new();
- if (*acct)
- gnc_account_sel_set_account (GNC_ACCOUNT_SEL(ddc->acct_combo), *acct, FALSE);
- gtk_box_pack_start (GTK_BOX(acct_box), ddc->acct_combo, TRUE, TRUE, 0);
+ acct_box = glade_xml_get_widget (xml, "acct_hbox");
+ ddc->acct_combo = gnc_account_sel_new();
+ if (*acct)
+ gnc_account_sel_set_account (GNC_ACCOUNT_SEL(ddc->acct_combo), *acct, FALSE);
+ gtk_box_pack_start (GTK_BOX(acct_box), ddc->acct_combo, TRUE, TRUE, 0);
- date_box = glade_xml_get_widget (xml, "date_box");
- ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
- gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
+ date_box = glade_xml_get_widget (xml, "date_box");
+ ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
+ gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
- if (parent)
- gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
+ if (parent)
+ gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
- build_date_close_window (hbox, message);
+ build_date_close_window (hbox, message);
- /* Set the labels */
- label = glade_xml_get_widget (xml, "date_label");
- gtk_label_set_text (GTK_LABEL (label), date_label_message);
- label = glade_xml_get_widget (xml, "acct_label");
- gtk_label_set_text (GTK_LABEL (label), acct_label_message);
+ /* Set the labels */
+ label = glade_xml_get_widget (xml, "date_label");
+ gtk_label_set_text (GTK_LABEL (label), date_label_message);
+ label = glade_xml_get_widget (xml, "acct_label");
+ gtk_label_set_text (GTK_LABEL (label), acct_label_message);
- /* Set the date widget */
- gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *date);
+ /* Set the date widget */
+ gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *date);
- /* Setup the account widget */
- fill_in_acct_info (ddc, FALSE);
+ /* Setup the account widget */
+ fill_in_acct_info (ddc, FALSE);
- /* Setup signals */
- glade_xml_signal_autoconnect_full( xml,
- gnc_glade_autoconnect_full_func,
- ddc);
+ /* Setup signals */
+ glade_xml_signal_autoconnect_full( xml,
+ gnc_glade_autoconnect_full_func,
+ ddc);
- gtk_widget_show_all (ddc->dialog);
+ gtk_widget_show_all (ddc->dialog);
- gtk_widget_hide_all (glade_xml_get_widget (xml, "postdate_label"));
- gtk_widget_hide_all (glade_xml_get_widget (xml, "post_date"));
- gtk_widget_hide_all (glade_xml_get_widget (xml, "memo_entry"));
- gtk_widget_hide_all (glade_xml_get_widget (xml, "memo_label"));
+ gtk_widget_hide_all (glade_xml_get_widget (xml, "postdate_label"));
+ gtk_widget_hide_all (glade_xml_get_widget (xml, "post_date"));
+ gtk_widget_hide_all (glade_xml_get_widget (xml, "memo_entry"));
+ gtk_widget_hide_all (glade_xml_get_widget (xml, "memo_label"));
- ddc->retval = FALSE;
- while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK) {
- /* If reponse is OK but flag is not set, try again */
- if (ddc->retval)
- break;
- }
+ ddc->retval = FALSE;
+ while (gtk_dialog_run (GTK_DIALOG (ddc->dialog)) == GTK_RESPONSE_OK)
+ {
+ /* If reponse is OK but flag is not set, try again */
+ if (ddc->retval)
+ break;
+ }
- gtk_widget_destroy(ddc->dialog);
- retval = ddc->retval;
- *acct = ddc->acct;
- g_free (ddc);
+ gtk_widget_destroy(ddc->dialog);
+ retval = ddc->retval;
+ *acct = ddc->acct;
+ g_free (ddc);
- return retval;
+ return retval;
}
Modified: gnucash/trunk/src/business/business-gnome/dialog-date-close.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-date-close.h 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-date-close.h 2010-03-02 21:41:05 UTC (rev 18789)
@@ -31,13 +31,13 @@
gboolean
gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
- const char *label_message,
- gboolean ok_is_default,
- /* Returned data ... */
- Timespec *date);
+ const char *label_message,
+ gboolean ok_is_default,
+ /* Returned data ... */
+ Timespec *date);
-/*
+/*
* Note that the dialog will "own" (and free) the acct_types list.
* it should be a list of GNCAccountTypes. If memo is non-NULL,
* it will g_malloc() a string. The caller should g_free() it.
@@ -47,17 +47,17 @@
gboolean
gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
- const char *ddue_label_message,
- const char *post_label_message,
- const char *acct_label_message,
- const char *question_check_message,
- gboolean ok_is_default,
- gboolean set_default_acct,
- GList * acct_types, GList * acct_commodities,
- QofBook *book, GncBillTerm *terms,
- /* Returned Data... */
- Timespec *ddue, Timespec *post,
- char **memo, Account **acct, gboolean *answer);
+ const char *ddue_label_message,
+ const char *post_label_message,
+ const char *acct_label_message,
+ const char *question_check_message,
+ gboolean ok_is_default,
+ gboolean set_default_acct,
+ GList * acct_types, GList * acct_commodities,
+ QofBook *book, GncBillTerm *terms,
+ /* Returned Data... */
+ Timespec *ddue, Timespec *post,
+ char **memo, Account **acct, gboolean *answer);
#define gnc_dialog_dates_acct_parented(parent, message, \
ddue_label_message, \
@@ -80,15 +80,15 @@
/* Returned Data... */ \
ddue, post, \
memo, acct, NULL) \
+
-
gboolean
gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
- const char *date_label_message,
- const char *acct_label_message,
- gboolean ok_is_default,
- GList * acct_types, QofBook *book,
- /* Returned Data... */
- Timespec *date, Account **acct);
+ const char *date_label_message,
+ const char *acct_label_message,
+ gboolean ok_is_default,
+ GList * acct_types, QofBook *book,
+ /* Returned Data... */
+ Timespec *date, Account **acct);
#endif /* _DIALOG_DATE_CLOSE_H */
Modified: gnucash/trunk/src/business/business-gnome/dialog-employee.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-employee.c 2010-03-02 21:40:28 UTC (rev 18788)
+++ gnucash/trunk/src/business/business-gnome/dialog-employee.c 2010-03-02 21:41:05 UTC (rev 18789)
@@ -61,534 +61,558 @@
typedef enum
{
- NEW_EMPLOYEE,
- EDIT_EMPLOYEE
+ NEW_EMPLOYEE,
+ EDIT_EMPLOYEE
} EmployeeDialogType;
-struct _employee_select_window {
- QofBook * book;
- QueryNew * q;
+struct _employee_select_window
+{
+ QofBook * book;
+ QueryNew * q;
};
-struct _employee_window {
- GtkWidget * dialog;
+struct _employee_window
+{
+ GtkWidget * dialog;
- GtkWidget * id_entry;
- GtkWidget * username_entry;
+ GtkWidget * id_entry;
+ GtkWidget * username_entry;
- GtkWidget * name_entry;
- GtkWidget * addr1_entry;
- GtkWidget * addr2_entry;
- GtkWidget * addr3_entry;
- GtkWidget * addr4_entry;
- GtkWidget * phone_entry;
- GtkWidget * fax_entry;
- GtkWidget * email_entry;
+ GtkWidget * name_entry;
+ GtkWidget * addr1_entry;
+ GtkWidget * addr2_entry;
+ GtkWidget * addr3_entry;
+ GtkWidget * addr4_entry;
+ GtkWidget * phone_entry;
+ GtkWidget * fax_entry;
+ GtkWidget * email_entry;
- GtkWidget * language_entry;
+ GtkWidget * language_entry;
- GtkWidget * workday_amount;
- GtkWidget * rate_amount;
- GtkWidget * currency_edit;
- GtkWidget * ccard_acct_check;
- GtkWidget * ccard_acct_sel;
+ GtkWidget * workday_amount;
+ GtkWidget * rate_amount;
+ GtkWidget * currency_edit;
+ GtkWidget * ccard_acct_check;
+ GtkWidget * ccard_acct_sel;
- GtkWidget * active_check;
+ GtkWidget * active_check;
- /* ACL? */
+ /* ACL? */
- EmployeeDialogType dialog_type;
- GUID employee_guid;
- gint component_id;
- QofBook * book;
- GncEmployee * created_employee;
+ EmployeeDialogType dialog_type;
+ GUID employee_guid;
+ gint component_id;
+ QofBook * book;
+ GncEmployee * created_employee;
};
static GncEmployee *
ew_get_employee (EmployeeWindow *ew)
{
- if (!ew)
- return NULL;
+ if (!ew)
+ return NULL;
- return gncEmployeeLookup (ew->book, &ew->employee_guid);
+ return gncEmployeeLookup (ew->book, &ew->employee_guid);
}
static void gnc_ui_to_employee (EmployeeWindow *ew, GncEmployee *employee)
{
- GncAddress *addr;
+ GncAddress *addr;
- addr = gncEmployeeGetAddr (employee);
+ addr = gncEmployeeGetAddr (employee);
- gnc_suspend_gui_refresh ();
+ gnc_suspend_gui_refresh ();
- gncEmployeeBeginEdit (employee);
+ gncEmployeeBeginEdit (employee);
- gncEmployeeSetID (employee, gtk_editable_get_chars
- (GTK_EDITABLE (ew->id_entry), 0, -1));
- gncEmployeeSetUsername (employee, gtk_editable_get_chars
- (GTK_EDITABLE (ew->username_entry), 0, -1));
+ gncEmployeeSetID (employee, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->id_entry), 0, -1));
+ gncEmployeeSetUsername (employee, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->username_entry), 0, -1));
- gncAddressSetName (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->name_entry), 0, -1));
- gncAddressSetAddr1 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->addr1_entry), 0, -1));
- gncAddressSetAddr2 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->addr2_entry), 0, -1));
- gncAddressSetAddr3 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->addr3_entry), 0, -1));
- gncAddressSetAddr4 (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->addr4_entry), 0, -1));
- gncAddressSetPhone (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->phone_entry), 0, -1));
- gncAddressSetFax (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->fax_entry), 0, -1));
- gncAddressSetEmail (addr, gtk_editable_get_chars
- (GTK_EDITABLE (ew->email_entry), 0, -1));
+ gncAddressSetName (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->name_entry), 0, -1));
+ gncAddressSetAddr1 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->addr1_entry), 0, -1));
+ gncAddressSetAddr2 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->addr2_entry), 0, -1));
+ gncAddressSetAddr3 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->addr3_entry), 0, -1));
+ gncAddressSetAddr4 (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->addr4_entry), 0, -1));
+ gncAddressSetPhone (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->phone_entry), 0, -1));
+ gncAddressSetFax (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->fax_entry), 0, -1));
+ gncAddressSetEmail (addr, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->email_entry), 0, -1));
- gncEmployeeSetActive (employee, gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (ew->active_check)));
- gncEmployeeSetLanguage (employee, gtk_editable_get_chars
- (GTK_EDITABLE (ew->language_entry), 0, -1));
+ gncEmployeeSetActive (employee, gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (ew->active_check)));
+ gncEmployeeSetLanguage (employee, gtk_editable_get_chars
+ (GTK_EDITABLE (ew->language_entry), 0, -1));
- /* Parse and set the workday and rate amounts */
- gncEmployeeSetWorkday (employee, gnc_amount_edit_get_amount
- (GNC_AMOUNT_EDIT (ew->workday_amount)));
- gncEmployeeSetRate (employee, gnc_amount_edit_get_amount
- (GNC_AMOUNT_EDIT (ew->rate_amount)));
- gncEmployeeSetCurrency (employee, gnc_currency_edit_get_currency
- (GNC_CURRENCY_EDIT (ew->currency_edit)));
+ /* Parse and set the workday and rate amounts */
+ gncEmployeeSetWorkday (employee, gnc_amount_edit_get_amount
+ (GNC_AMOUNT_EDIT (ew->workday_amount)));
+ gncEmployeeSetRate (employee, gnc_amount_edit_get_amount
+ (GNC_AMOUNT_EDIT (ew->rate_amount)));
+ gncEmployeeSetCurrency (employee, gnc_currency_edit_get_currency
+ (GNC_CURRENCY_EDIT (ew->currency_edit)));
- /* Fill in the CCard Acct */
- gncEmployeeSetCCard (employee,
- (gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (ew->ccard_acct_check)) ?
- gnc_account_sel_get_account
- (GNC_ACCOUNT_SEL (ew->ccard_acct_sel)) : NULL));
+ /* Fill in the CCard Acct */
+ gncEmployeeSetCCard (employee,
+ (gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (ew->ccard_acct_check)) ?
+ gnc_account_sel_get_account
+ (GNC_ACCOUNT_SEL (ew->ccard_acct_sel)) : NULL));
- gncEmployeeCommitEdit (employee);
- gnc_resume_gui_refresh ();
+ gncEmployeeCommitEdit (employee);
+ gnc_resume_gui_refresh ();
}
#if 0
static gboolean check_edit_amount (GtkWidget *dialog, GtkWidget *amount,
- gnc_numeric *min, gnc_numeric *max,
- const char * error_message)
+ gnc_numeric *min, gnc_numeric *max,
+ const char * error_message)
{
- if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount))) {
- if (error_message)
- gnc_error_dialog (dialog, error_message);
- return TRUE;
- }
- /* We've got a valid-looking number; check mix/max */
- if (min || max) {
- gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount));
- if ((min && gnc_numeric_compare (*min, val) > 0) ||
- (max && gnc_numeric_compare (val, *max) > 0)) {
- if (error_message)
- gnc_error_dialog (dialog, error_message);
- return TRUE;
+ if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount)))
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, error_message);
+ return TRUE;
}
- }
- return FALSE;
+ /* We've got a valid-looking number; check mix/max */
+ if (min || max)
+ {
+ gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount));
+ if ((min && gnc_numeric_compare (*min, val) > 0) ||
+ (max && gnc_numeric_compare (val, *max) > 0))
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, error_message);
+ return TRUE;
+ }
+ }
+ return FALSE;
}
#endif
-static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry,
- const char * error_message)
+static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry,
+ const char * error_message)
{
- const char *res = gtk_entry_get_text (GTK_ENTRY (entry));
- if (safe_strcmp (res, "") == 0) {
- if (error_message)
- gnc_error_dialog (dialog, "%s", error_message);
- return TRUE;
- }
- return FALSE;
+ const char *res = gtk_entry_get_text (GTK_ENTRY (entry));
+ if (safe_strcmp (res, "") == 0)
+ {
+ if (error_message)
+ gnc_error_dialog (dialog, "%s", error_message);
+ return TRUE;
+ }
+ return FALSE;
}
void
gnc_employee_window_ok_cb (GtkWidget *widget, gpointer data)
{
- EmployeeWindow *ew = data;
- gchar *string;
+ EmployeeWindow *ew = data;
+ gchar *string;
- /* Check for valid username */
- if (check_entry_nonempty (ew->dialog, ew->username_entry,
- _("You must enter a username.")))
- return;
+ /* Check for valid username */
+ if (check_entry_nonempty (ew->dialog, ew->username_entry,
+ _("You must enter a username.")))
+ return;
- /* Check for valid username */
- if (check_entry_nonempty (ew->dialog, ew->name_entry,
- _("You must enter the employee's name.")))
- return;
+ /* Check for valid username */
+ if (check_entry_nonempty (ew->dialog, ew->name_entry,
+ _("You must enter the employee's name.")))
+ return;
- /* Make sure we have an address */
- if (check_entry_nonempty (ew->dialog, ew->addr1_entry, NULL) &&
- check_entry_nonempty (ew->dialog, ew->addr2_entry, NULL) &&
- check_entry_nonempty (ew->dialog, ew->addr3_entry, NULL) &&
- check_entry_nonempty (ew->dialog, ew->addr4_entry, NULL)) {
- const char *msg = _("You must enter an address.");
- gnc_error_dialog (ew->dialog, "%s", msg);
- return;
- }
+ /* Make sure we have an address */
+ if (check_entry_nonempty (ew->dialog, ew->addr1_entry, NULL) &&
+ check_entry_nonempty (ew->dialog, ew->addr2_entry, NULL) &&
+ check_entry_nonempty (ew->dialog, ew->addr3_entry, NULL) &&
+ check_entry_nonempty (ew->dialog, ew->addr4_entry, NULL))
+ {
+ const char *msg = _("You must enter an address.");
+ gnc_error_dialog (ew->dialog, "%s", msg);
+ return;
+ }
- /* Set the employee id if one has not been chosen */
- if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (ew->id_entry)), "") == 0) {
- string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-