mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18789 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -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 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
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 @@ gnc_address_finalize(GObject* addrp)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ gncAddressFree (GncAddress *addr)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ typedef struct _gncAddressClass GncAddressClass;
|
||||
(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 @@ void gncAddressCommitEdit (GncAddress *addr);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Set functions
|
||||
/** @name Set functions
|
||||
@{ */
|
||||
|
||||
void gncAddressSetName (GncAddress *addr, const char *name);
|
||||
@@ -116,7 +116,7 @@ void gncAddressSetEmail (GncAddress *addr, const char *email);
|
||||
void gncAddressClearDirty (GncAddress *address);
|
||||
/** @} */
|
||||
|
||||
/** @name Get Functions
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
|
||||
const char * gncAddressGetName (const GncAddress *addr);
|
||||
@@ -131,10 +131,10 @@ const char * gncAddressGetEmail (const GncAddress *addr);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,13 +79,14 @@ GType gnc_billterm_get_type(void);
|
||||
|
||||
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 gncBillTermBeginEdit (GncBillTerm *term);
|
||||
void gncBillTermCommitEdit (GncBillTerm *term);
|
||||
/** @} */
|
||||
|
||||
/** @name Set Functions
|
||||
/** @name Set Functions
|
||||
@{
|
||||
*/
|
||||
void gncBillTermSetName (GncBillTerm *term, const char *name);
|
||||
@@ -110,10 +111,10 @@ void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @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);
|
||||
|
||||
@@ -42,9 +42,9 @@ gboolean gncBillTermGetInvisible (const GncBillTerm *term);
|
||||
|
||||
/** The gncCloneBillTerm() routine makes a copy of the indicated
|
||||
* bill term, placing it in the indicated book. It copies
|
||||
* the name, description, type, due-days, discount, etc.
|
||||
* 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 @@ GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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 @@ XXX TODO:
|
||||
-- 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 @@ XXX TODO:
|
||||
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 @@ gncBillTermCopyAll (QofBook *dest_book, QofBook *src_book)
|
||||
partition (QofBook *dest_book, QofBook *src_book)
|
||||
{
|
||||
|
||||
/* Copy all bill terms first, since the CustomerCopy expects
|
||||
* these to be in place already. */
|
||||
/* XXX not strictly needed, the customer can pull their own .. ? */
|
||||
gncBillTermCopyAll (dest_book, src_book);
|
||||
/* 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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* gncBusiness.c -- Business helper functions
|
||||
* gncBusiness.c -- Business helper functions
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@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) {}
|
||||
|
||||
@@ -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.
|
||||
@{ */
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -78,7 +78,7 @@ typedef struct _gncCustomerClass GncCustomerClass;
|
||||
(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 gncCustomerBeginEdit (GncCustomer *customer);
|
||||
void gncCustomerCommitEdit (GncCustomer *customer);
|
||||
/** @} */
|
||||
|
||||
/** @name Set Functions
|
||||
/** @name Set Functions
|
||||
@{ */
|
||||
|
||||
void gncCustomerSetID (GncCustomer *customer, const char *id);
|
||||
@@ -107,10 +107,10 @@ void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @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);
|
||||
|
||||
@@ -37,7 +37,7 @@ gint64 gncCustomerNextID (QofBook *book);
|
||||
/** The gncCloneCustomer() routine makes a copy of the indicated
|
||||
* customer, placing it in the indicated book. It copies
|
||||
* the addresses, credits, currency, billing terms and jobs.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* 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);
|
||||
|
||||
@@ -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 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
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 @@ gnc_employee_finalize(GObject* empp)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
|
||||
|
||||
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 @@ void gncEmployeeCommitEdit (GncEmployee *employee)
|
||||
|
||||
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 const char * _gncEmployeePrintable (gpointer item)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef struct _gncEmployeeClass GncEmployeeClass;
|
||||
(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 @@ void gncEmployeeCommitEdit (GncEmployee *employee);
|
||||
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 @@ void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @name Get Functions
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
QofBook * gncEmployeeGetBook (GncEmployee *employee);
|
||||
const char * gncEmployeeGetID (const GncEmployee *employee);
|
||||
|
||||
@@ -38,7 +38,7 @@ gint64 gncEmployeeNextID (QofBook *book);
|
||||
* 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 @@ GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 @@ gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how);
|
||||
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 @@ void gncEntryDestroy (GncEntry *entry);
|
||||
|
||||
/* 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 gncEntrySetNotes (GncEntry *entry, const char *notes);
|
||||
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 qofEntrySetInvDiscType (GncEntry *entry, const char *type);
|
||||
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 gncEntrySetBillable (GncEntry *entry, gboolean billable);
|
||||
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 @@ const char * gncEntryGetNotes (const GncEntry *notes);
|
||||
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 @@ gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry);
|
||||
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 @@ GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry);
|
||||
|
||||
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 @@ AccountValueList * gncEntryReturnTaxValues (GncEntry *entry, gboolean is_inv);
|
||||
* 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 * gncEntryGetInvoice (const GncEntry *entry);
|
||||
GncInvoice * gncEntryGetBill (const GncEntry *entry);
|
||||
|
||||
/** Return a pointer to the instance gncEntry that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* 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);
|
||||
|
||||
@@ -54,7 +54,7 @@ GncEntry * gncCloneEntry (GncEntry *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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@MIT.EDU>
|
||||
@author Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*/
|
||||
@@ -64,13 +64,13 @@ typedef struct _gncInvoiceClass GncInvoiceClass;
|
||||
(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 gncBillRemovePrice (GncInvoice *bill, GNCPrice *price);
|
||||
*/
|
||||
void gncInvoiceSortEntries (GncInvoice *invoice);
|
||||
|
||||
/** @name Get Functions
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
const char * gncInvoiceGetID (const GncInvoice *invoice);
|
||||
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
|
||||
@@ -112,7 +112,7 @@ GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
|
||||
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 @@ GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity* commodity);
|
||||
*/
|
||||
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 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
|
||||
*/
|
||||
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 * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
|
||||
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);
|
||||
|
||||
@@ -44,9 +44,9 @@ void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
|
||||
|
||||
/** The gncCloneInvoice() routine makes a copy of the indicated
|
||||
* invoice, placing it in the indicated book. It copies
|
||||
* the name, description, type, due-days, discount, etc.
|
||||
* 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 @@ GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
@@ -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 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
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 @@ gnc_job_finalize(GObject* jobp)
|
||||
|
||||
static void
|
||||
gnc_job_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GncJob *job;
|
||||
|
||||
g_return_if_fail(GNC_IS_JOB(object));
|
||||
|
||||
job = GNC_JOB(object);
|
||||
switch (prop_id) {
|
||||
case PROP_NAME:
|
||||
g_value_set_string(value, job->name);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_job_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GncJob *job;
|
||||
|
||||
g_return_if_fail(GNC_IS_JOB(object));
|
||||
|
||||
job = GNC_JOB(object);
|
||||
switch (prop_id) {
|
||||
case PROP_NAME:
|
||||
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:
|
||||
g_value_set_string(value, job->name);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_job_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GncJob *job;
|
||||
|
||||
g_return_if_fail(GNC_IS_JOB(object));
|
||||
|
||||
job = GNC_JOB(object);
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
gncJobSetName(job, g_value_get_string(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,113 +141,114 @@ static void
|
||||
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 @@ gncJobObtainTwin (GncJob *from, QofBook *book)
|
||||
|
||||
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 @@ void gncJobCommitEdit (GncJob *job)
|
||||
|
||||
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 @@ int gncJobCompare (const GncJob * a, const GncJob *b) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
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 @@ gnc_order_finalize(GObject* orderp)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ gncOrderObtainTwin (GncOrder *from, QofBook *book)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ int gncOrderCompare (const GncOrder *a, const GncOrder *b);
|
||||
gboolean gncOrderIsClosed (const GncOrder *order);
|
||||
|
||||
/** Return a pointer to the instance gncOrder that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* 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);
|
||||
|
||||
@@ -49,7 +49,7 @@ GncOrder * gncCloneOrder (GncOrder *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
@@ -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 @@ KvpFrame* gncOwnerGetSlots(GncOwner* owner)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -42,16 +42,17 @@ typedef struct _gncOwner GncOwner;
|
||||
#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 @@ gncOwnerRegister(void);
|
||||
#ifndef SWIG
|
||||
|
||||
/** \struct GncOwner */
|
||||
struct _gncOwner {
|
||||
GncOwnerType type; /**< Customer, Job, Vendor, Employee or Undefined. */
|
||||
union {
|
||||
gpointer undefined;
|
||||
GncCustomer * customer;
|
||||
GncJob * job;
|
||||
GncVendor * vendor;
|
||||
GncEmployee * employee;
|
||||
} owner; /**< holds the pointer to the owner object. */
|
||||
gpointer qof_temp; /**< Set type independently of the owner. */
|
||||
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 */
|
||||
|
||||
@@ -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 *
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
@param Timespec modtime;
|
||||
@param Timespec modtime;
|
||||
@param gint64 refcount;
|
||||
@param GncTaxTable * parent; if non-null, we are an immutable child
|
||||
@param GncTaxTable * child; if non-null, we have not changed
|
||||
@param GncTaxTable * parent; if non-null, we are an immutable child
|
||||
@param GncTaxTable * child; if non-null, we have not changed
|
||||
@param gboolean invisible;
|
||||
@param GList * children; list of children for disconnection
|
||||
@param GList * children; list of children for disconnection
|
||||
*/
|
||||
typedef struct _gncTaxTable GncTaxTable;
|
||||
typedef struct _gncTaxTableClass GncTaxTableClass;
|
||||
@@ -90,16 +90,18 @@ GType gnc_taxtable_get_type(void);
|
||||
* How to interpret the amount.
|
||||
* You can interpret it as a VALUE or a PERCENT.
|
||||
*/
|
||||
typedef enum {
|
||||
GNC_AMT_TYPE_VALUE = 1, /**< tax is a number */
|
||||
GNC_AMT_TYPE_PERCENT /**< tax is a percentage */
|
||||
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 @@ gboolean gncAmountStringToType (const char *str, GncAmountType *type);
|
||||
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 gncTaxTableChanged (GncTaxTable *table);
|
||||
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 @@ int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *
|
||||
|
||||
/************************************************/
|
||||
|
||||
struct _gncAccountValue {
|
||||
Account * account;
|
||||
gnc_numeric value;
|
||||
struct _gncAccountValue
|
||||
{
|
||||
Account * account;
|
||||
gnc_numeric value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
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 @@ gnc_vendor_finalize(GObject* vendorp)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ gncVendorObtainTwin (GncVendor *from, QofBook *book)
|
||||
|
||||
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 @@ qofVendorSetTaxIncluded(GncVendor *vendor, const char* type_string)
|
||||
|
||||
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 @@ void gncVendorCommitEdit (GncVendor *vendor)
|
||||
|
||||
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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
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 @@ gboolean gncVendorIsDirty (const GncVendor *vendor)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
/** @addtogroup Vendor
|
||||
@{ */
|
||||
/** @file gncVendor.h
|
||||
@brief Vendor Interface
|
||||
@brief Vendor Interface
|
||||
@author Copyright (C) 2001,2002 Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -100,14 +100,14 @@ GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor);
|
||||
|
||||
/** @} */
|
||||
/** 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);
|
||||
|
||||
@@ -48,7 +48,7 @@ GncVendor * gncCloneVendor (GncVendor *from, QofBook *);
|
||||
* 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);
|
||||
|
||||
@@ -49,15 +49,15 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ typedef GncAddress* (*AddressGetterFunc)( const gpointer );
|
||||
|
||||
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 @@ get_gvalue_address( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpoi
|
||||
|
||||
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 ===================== */
|
||||
|
||||
@@ -57,55 +57,65 @@ static void set_invisible( gpointer data, gboolean value );
|
||||
|
||||
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 @@ load_all_billterms( GncSqlBackend* be )
|
||||
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 @@ gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
|
||||
/* ================================================================= */
|
||||
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_billterm_sql_initialize( void )
|
||||
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 ===================== */
|
||||
|
||||
@@ -58,44 +58,51 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ load_all_customers( GncSqlBackend* be )
|
||||
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,17 +147,20 @@ load_all_customers( GncSqlBackend* be )
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,17 +168,18 @@ create_customer_tables( GncSqlBackend* be )
|
||||
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 @@ customer_should_be_saved( GncCustomer *customer )
|
||||
{
|
||||
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 @@ customer_should_be_saved( GncCustomer *customer )
|
||||
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 @@ gnc_customer_sql_initialize( void )
|
||||
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 );
|
||||
|
||||
@@ -58,18 +58,20 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ static GncEmployee*
|
||||
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 @@ load_all_employees( GncSqlBackend* be )
|
||||
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,17 +140,20 @@ load_all_employees( GncSqlBackend* be )
|
||||
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 @@ save_employee( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
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 @@ employee_should_be_saved( GncEmployee *employee )
|
||||
{
|
||||
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 @@ employee_should_be_saved( GncEmployee *employee )
|
||||
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 @@ gnc_employee_sql_initialize( void )
|
||||
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 );
|
||||
|
||||
@@ -65,94 +65,109 @@ static void entry_set_bill( gpointer pObject, gpointer val );
|
||||
|
||||
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 @@ load_all_entries( GncSqlBackend* be )
|
||||
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,20 +212,23 @@ load_all_entries( GncSqlBackend* be )
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,9 +236,9 @@ create_entry_tables( GncSqlBackend* be )
|
||||
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 @@ save_entry( GncSqlBackend* be, QofInstance* inst )
|
||||
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 @@ gnc_entry_sql_initialize( void )
|
||||
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 );
|
||||
|
||||
@@ -59,47 +59,58 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ load_all_invoices( GncSqlBackend* be )
|
||||
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,20 +155,23 @@ load_all_invoices( GncSqlBackend* be )
|
||||
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 @@ static gboolean
|
||||
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 @@ invoice_should_be_saved( GncInvoice *invoice )
|
||||
{
|
||||
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 @@ invoice_should_be_saved( GncInvoice *invoice )
|
||||
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 @@ gnc_invoice_sql_initialize( void )
|
||||
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 ===================== */
|
||||
|
||||
@@ -54,35 +54,40 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ load_all_jobs( GncSqlBackend* be )
|
||||
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 @@ load_all_jobs( GncSqlBackend* be )
|
||||
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 @@ create_job_tables( GncSqlBackend* be )
|
||||
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 @@ job_should_be_saved( GncJob *job )
|
||||
{
|
||||
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 @@ job_should_be_saved( GncJob *job )
|
||||
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 @@ gnc_job_sql_initialize( void )
|
||||
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 );
|
||||
|
||||
@@ -55,35 +55,36 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ load_all_orders( GncSqlBackend* be )
|
||||
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 @@ load_all_orders( GncSqlBackend* be )
|
||||
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 @@ create_order_tables( GncSqlBackend* be )
|
||||
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 @@ order_should_be_saved( GncOrder *order )
|
||||
{
|
||||
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 @@ order_should_be_saved( GncOrder *order )
|
||||
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 @@ gnc_order_sql_initialize( void )
|
||||
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 ===================== */
|
||||
|
||||
@@ -54,134 +54,147 @@ load_owner( const GncSqlBackend* be, GncSqlRow* row,
|
||||
{
|
||||
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 @@ add_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
|
||||
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 ===================== */
|
||||
|
||||
@@ -48,7 +48,8 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 void set_parent( gpointer pObject, gpointer pValue );
|
||||
|
||||
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 tt_col_table[] =
|
||||
|
||||
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 @@ get_obj_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
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 @@ set_obj_guid( gpointer pObject, gpointer pValue )
|
||||
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 @@ load_taxtable_entries( GncSqlBackend* be, GncTaxTable* tt )
|
||||
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 @@ static void
|
||||
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 @@ load_all_taxtables( GncSqlBackend* be )
|
||||
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,26 +274,32 @@ load_all_taxtables( GncSqlBackend* be )
|
||||
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 @@ delete_all_tt_entries( GncSqlBackend* be, const GUID* guid )
|
||||
{
|
||||
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 @@ save_taxtable( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
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 @@ gnc_taxtable_sql_initialize( void )
|
||||
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 ===================== */
|
||||
|
||||
|
||||
@@ -63,40 +63,45 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
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 @@ load_all_vendors( GncSqlBackend* be )
|
||||
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 @@ load_all_vendors( GncSqlBackend* be )
|
||||
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 @@ save_vendor( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
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 @@ vendor_should_be_saved( GncVendor *vendor )
|
||||
{
|
||||
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 @@ vendor_should_be_saved( GncVendor *vendor )
|
||||
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 @@ gnc_vendor_sql_initialize( void )
|
||||
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 );
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-address.c
|
||||
* object definition/initialization for Address
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2005 Neil Williams <linux@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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-business.c
|
||||
* Test the business code.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -42,96 +42,97 @@ static const char * printable (gpointer obj);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-customer.c
|
||||
* Test the customer object (without Guile/Scheme)
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*
|
||||
@@ -37,184 +37,185 @@ static int count = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-employee.c
|
||||
* Test the employee object (without Guile).
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*
|
||||
@@ -37,194 +37,195 @@ static int count = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-job.c
|
||||
* Test the job object.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*
|
||||
@@ -37,211 +37,216 @@ static int count = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*********************************************************************
|
||||
* test-load-module.c
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*********************************************************************
|
||||
* test-vendor.c
|
||||
* Test the vendor object.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
||||
*
|
||||
@@ -36,193 +36,198 @@ static int count = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ const gchar *address_version_string = "2.0.0";
|
||||
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 @@ gnc_address_to_dom_tree (const char *tag, GncAddress *addr)
|
||||
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 @@ gnc_address_to_dom_tree (const char *tag, GncAddress *addr)
|
||||
|
||||
struct address_pdata
|
||||
{
|
||||
GncAddress *address;
|
||||
GncAddress *address;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
@@ -100,11 +100,11 @@ set_string(xmlNodePtr node, GncAddress* addr,
|
||||
{
|
||||
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 @@ address_email_handler (xmlNodePtr node, gpointer addr_pdata)
|
||||
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 @@ address_ns(FILE *out)
|
||||
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);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,54 +86,54 @@ customer_dom_tree_create (GncCustomer *cust)
|
||||
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 @@ customer_dom_tree_create (GncCustomer *cust)
|
||||
|
||||
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 @@ customer_guid_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
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 @@ customer_terms_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
g_assert(term);
|
||||
g_free (guid);
|
||||
gncCustomerSetTerms (pdata->customer, term);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -253,7 +256,7 @@ customer_shipaddr_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
struct customer_pdata *pdata = cust_pdata;
|
||||
|
||||
return gnc_dom_tree_to_address (node,
|
||||
gncCustomerGetShipAddr(pdata->customer));
|
||||
gncCustomerGetShipAddr(pdata->customer));
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +275,7 @@ customer_taxincluded_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncCustomerSetTaxIncluded(pdata->customer, type);
|
||||
gncCustomerSetTaxIncluded(pdata->customer, type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -338,13 +341,15 @@ customer_taxtable_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
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 @@ customer_taxtableoverride_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
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 @@ dom_tree_to_customer (xmlNodePtr node, QofBook *book)
|
||||
&cust_pdata);
|
||||
|
||||
if (successful)
|
||||
gncCustomerCommitEdit (cust_pdata.customer);
|
||||
gncCustomerCommitEdit (cust_pdata.customer);
|
||||
else
|
||||
{
|
||||
PERR ("failed to parse customer tree");
|
||||
@@ -413,9 +419,9 @@ dom_tree_to_customer (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_customer_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_customer_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_customer_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ const gchar *employee_version_string = "2.0.0";
|
||||
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 @@ employee_dom_tree_create (GncEmployee *employee)
|
||||
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 @@ employee_dom_tree_create (GncEmployee *employee)
|
||||
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 @@ employee_dom_tree_create (GncEmployee *employee)
|
||||
|
||||
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 @@ employee_guid_handler (xmlNodePtr node, gpointer employee_pdata)
|
||||
|
||||
/* 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 @@ employee_active_handler (xmlNodePtr node, gpointer employee_pdata)
|
||||
|
||||
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 @@ employee_slots_handler (xmlNodePtr node, gpointer employee_pdata)
|
||||
{
|
||||
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 @@ dom_tree_to_employee (xmlNodePtr node, QofBook *book)
|
||||
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 @@ dom_tree_to_employee (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_employee_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_employee_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_employee_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -95,15 +95,15 @@ const gchar *entry_version_string = "2.0.0";
|
||||
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 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
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 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
|
||||
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 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
|
||||
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 @@ set_account(xmlNodePtr node, struct entry_pdata *pdata,
|
||||
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 @@ set_taxtable (xmlNodePtr node, struct entry_pdata *pdata,
|
||||
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 @@ entry_guid_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
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 @@ entry_idisctype_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncEntrySetInvDiscountType(pdata->entry, type);
|
||||
gncEntrySetInvDiscountType(pdata->entry, type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -442,7 +449,7 @@ entry_idischow_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncEntrySetInvDiscountHow(pdata->entry, how);
|
||||
gncEntrySetInvDiscountHow(pdata->entry, how);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -516,15 +523,15 @@ entry_billable_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
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 @@ entry_billpayment_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncEntrySetBillPayment(pdata->entry, type);
|
||||
gncEntrySetBillPayment(pdata->entry, type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -560,11 +567,12 @@ entry_order_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
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 @@ entry_invoice_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
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 @@ entry_bill_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
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 @@ entry_price_handler (xmlNodePtr node, gpointer entry_pdata)
|
||||
/* 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 @@ dom_tree_to_entry (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ dom_tree_to_entry (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_entry_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_entry_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_entry_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -75,15 +75,15 @@ const gchar *invoice_version_string = "2.0.0";
|
||||
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 @@ invoice_dom_tree_create (GncInvoice *invoice)
|
||||
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 @@ invoice_dom_tree_create (GncInvoice *invoice)
|
||||
|
||||
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 @@ invoice_guid_handler (xmlNodePtr node, gpointer invoice_pdata)
|
||||
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 @@ invoice_id_handler (xmlNodePtr node, gpointer invoice_pdata)
|
||||
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 @@ invoice_active_handler (xmlNodePtr node, gpointer invoice_pdata)
|
||||
|
||||
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 @@ invoice_terms_handler (xmlNodePtr node, gpointer invoice_pdata)
|
||||
g_assert(term);
|
||||
g_free (guid);
|
||||
gncInvoiceSetTerms (pdata->invoice, term);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -367,36 +370,37 @@ invoice_currency_handler (xmlNodePtr node, gpointer invoice_pdata)
|
||||
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 @@ dom_tree_to_invoice (xmlNodePtr node, QofBook *book)
|
||||
&invoice_pdata);
|
||||
|
||||
if (successful)
|
||||
gncInvoiceCommitEdit (invoice_pdata.invoice);
|
||||
gncInvoiceCommitEdit (invoice_pdata.invoice);
|
||||
else
|
||||
{
|
||||
PERR ("failed to parse invoice tree");
|
||||
@@ -444,9 +448,9 @@ dom_tree_to_invoice (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_invoice_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_invoice_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_invoice_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -71,21 +71,21 @@ job_dom_tree_create (GncJob *job)
|
||||
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 @@ job_dom_tree_create (GncJob *job)
|
||||
|
||||
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 @@ job_guid_handler (xmlNodePtr node, gpointer job_pdata)
|
||||
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 @@ job_reference_handler (xmlNodePtr node, gpointer job_pdata)
|
||||
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 @@ job_active_handler (xmlNodePtr node, gpointer job_pdata)
|
||||
|
||||
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 @@ job_active_handler (xmlNodePtr node, gpointer job_pdata)
|
||||
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 @@ dom_tree_to_job (xmlNodePtr node, QofBook *book)
|
||||
&job_pdata);
|
||||
|
||||
if (successful)
|
||||
gncJobCommitEdit (job_pdata.job);
|
||||
gncJobCommitEdit (job_pdata.job);
|
||||
else
|
||||
{
|
||||
PERR ("failed to parse job tree");
|
||||
@@ -231,9 +235,9 @@ dom_tree_to_job (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_job_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_job_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_job_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ const gchar *order_version_string = "2.0.0";
|
||||
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 @@ order_dom_tree_create (GncOrder *order)
|
||||
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 @@ order_dom_tree_create (GncOrder *order)
|
||||
|
||||
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 @@ order_guid_handler (xmlNodePtr node, gpointer order_pdata)
|
||||
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 @@ order_id_handler (xmlNodePtr node, gpointer order_pdata)
|
||||
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 @@ order_active_handler (xmlNodePtr node, gpointer order_pdata)
|
||||
|
||||
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 @@ order_active_handler (xmlNodePtr node, gpointer order_pdata)
|
||||
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 @@ dom_tree_to_order (xmlNodePtr node, QofBook *book)
|
||||
&order_pdata);
|
||||
|
||||
if (successful)
|
||||
gncOrderCommitEdit (order_pdata.order);
|
||||
gncOrderCommitEdit (order_pdata.order);
|
||||
else
|
||||
{
|
||||
PERR ("failed to parse order tree");
|
||||
@@ -274,9 +278,9 @@ dom_tree_to_order (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_order_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_order_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_order_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -61,22 +61,23 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
|
||||
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 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
|
||||
|
||||
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 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
|
||||
|
||||
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);
|
||||
g_free(txt);
|
||||
return 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);
|
||||
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 @@ gnc_dom_tree_to_owner (xmlNodePtr node, GncOwner *owner, QofBook *book)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -70,33 +70,33 @@ const gchar *taxtable_version_string = "2.0.0";
|
||||
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 @@ taxtable_dom_tree_create (GncTaxTable *table)
|
||||
|
||||
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 @@ taxtable_dom_tree_create (GncTaxTable *table)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -265,104 +270,109 @@ taxtable_guid_handler (xmlNodePtr node, gpointer taxtable_pdata)
|
||||
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 struct dom_tree_handler taxtable_handlers_v2[] = {
|
||||
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 @@ gnc_taxtable_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_taxtable_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_taxtable_end_handler(gpointer data_for_children,
|
||||
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 @@ taxtable_scrub_cb (QofInstance * table_p, gpointer list_p)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -81,45 +81,45 @@ vendor_dom_tree_create (GncVendor *vendor)
|
||||
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 @@ vendor_dom_tree_create (GncVendor *vendor)
|
||||
|
||||
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 @@ vendor_guid_handler (xmlNodePtr node, gpointer vendor_pdata)
|
||||
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 @@ vendor_terms_handler (xmlNodePtr node, gpointer vendor_pdata)
|
||||
g_assert(term);
|
||||
g_free (guid);
|
||||
gncVendorSetTerms (pdata->vendor, term);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -248,7 +251,7 @@ vendor_taxincluded_handler (xmlNodePtr node, gpointer vendor_pdata)
|
||||
g_free (str);
|
||||
|
||||
if (ret)
|
||||
gncVendorSetTaxIncluded(pdata->vendor, type);
|
||||
gncVendorSetTaxIncluded(pdata->vendor, type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -284,13 +287,15 @@ vendor_taxtable_handler (xmlNodePtr node, gpointer vendor_pdata)
|
||||
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 @@ vendor_slots_handler (xmlNodePtr node, gpointer vendor_pdata)
|
||||
{
|
||||
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 @@ dom_tree_to_vendor (xmlNodePtr node, QofBook *book)
|
||||
&vendor_pdata);
|
||||
|
||||
if (successful)
|
||||
gncVendorCommitEdit (vendor_pdata.vendor);
|
||||
gncVendorCommitEdit (vendor_pdata.vendor);
|
||||
else
|
||||
{
|
||||
PERR ("failed to parse vendor tree");
|
||||
@@ -357,9 +363,9 @@ dom_tree_to_vendor (xmlNodePtr node, QofBook *book)
|
||||
|
||||
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 @@ gnc_vendor_end_handler(gpointer data_for_children,
|
||||
|
||||
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 @@ gnc_vendor_end_handler(gpointer data_for_children,
|
||||
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 @@ gnc_vendor_end_handler(gpointer data_for_children,
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 @@ GList * gnc_business_commodities (GncOwner *owner);
|
||||
|
||||
/* 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 @@ void gnc_fill_account_select_combo (GtkWidget *combo, QofBook *book,
|
||||
* 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_taxincluded_optionmenu (GtkWidget *omenu, GncTaxIncluded *choice);
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 @@ make_name_label (char *name)
|
||||
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 @@ owner_get_value (GNCOption *option, GtkWidget *widget)
|
||||
/* 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 @@ customer_get_value (GNCOption *option, GtkWidget *widget)
|
||||
/* 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 @@ vendor_get_value (GNCOption *option, GtkWidget *widget)
|
||||
/* 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 @@ employee_get_value (GNCOption *option, GtkWidget *widget)
|
||||
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 @@ invoice_get_value (GNCOption *option, GtkWidget *widget)
|
||||
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 @@ taxtable_get_value (GNCOption *option, GtkWidget *widget)
|
||||
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]));
|
||||
}
|
||||
|
||||
@@ -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 @@ static gboolean
|
||||
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;
|
||||
}
|
||||
|
||||
if (!string_to_guid (ownerptr + 2, &guid))
|
||||
{
|
||||
result->error_message = g_strdup_printf (_("Bad URL: %s"), location);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
switch (type) {
|
||||
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;
|
||||
}
|
||||
|
||||
acc = xaccAccountLookup (&guid, gnc_get_current_book ());
|
||||
if (NULL == acc)
|
||||
/* Deal with acctptr, if it exists */
|
||||
if (acctptr)
|
||||
{
|
||||
result->error_message = g_strdup_printf (_("No such Account entity: %s"),
|
||||
location);
|
||||
return FALSE;
|
||||
if (strncmp ("acct=", acctptr, 5) != 0)
|
||||
{
|
||||
result->error_message = g_strdup_printf (_("Bad URL %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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
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;
|
||||
}
|
||||
|
||||
ddc->acct = acc;
|
||||
}
|
||||
|
||||
if (xaccAccountGetPlaceholder (acc)) {
|
||||
gnc_error_dialog (ddc->dialog, "%s",
|
||||
_("Placeholder account selected. Please try again."));
|
||||
return;
|
||||
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));
|
||||
}
|
||||
|
||||
ddc->acct = acc;
|
||||
}
|
||||
|
||||
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->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);
|
||||
/* 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);
|
||||
/* 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 the account widget */
|
||||
fill_in_acct_info (ddc, set_default_acct);
|
||||
/* Setup the account widget */
|
||||
fill_in_acct_info (ddc, set_default_acct);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Set the focus on the date widget */
|
||||
gnc_date_grab_focus (GNC_DATE_EDIT (ddc->post_date));
|
||||
/* Set the focus on the date widget */
|
||||
gnc_date_grab_focus (GNC_DATE_EDIT (ddc->post_date));
|
||||
|
||||
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;
|
||||
if (question_check_message)
|
||||
*answer = ddc->answer;
|
||||
g_free (ddc);
|
||||
gtk_widget_destroy(ddc->dialog);
|
||||
retval = ddc->retval;
|
||||
*acct = ddc->acct;
|
||||
if (question_check_message)
|
||||
*answer = ddc->answer;
|
||||
g_free (ddc);
|
||||
|
||||
return retval;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
|
||||
|
||||
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 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
|
||||
/* 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 */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -37,12 +37,12 @@ typedef struct _invoice_window InvoiceWindow;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BY_STANDARD = 0,
|
||||
BY_DATE,
|
||||
BY_DATE_ENTERED,
|
||||
BY_DESC,
|
||||
BY_QTY,
|
||||
BY_PRICE
|
||||
BY_STANDARD = 0,
|
||||
BY_DATE,
|
||||
BY_DATE_ENTERED,
|
||||
BY_DESC,
|
||||
BY_QTY,
|
||||
BY_PRICE
|
||||
} invoice_sort_type_t;
|
||||
|
||||
|
||||
|
||||
@@ -56,374 +56,394 @@ void gnc_job_name_changed_cb (GtkWidget *widget, gpointer data);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NEW_JOB,
|
||||
EDIT_JOB
|
||||
NEW_JOB,
|
||||
EDIT_JOB
|
||||
} JobDialogType;
|
||||
|
||||
struct _job_select_window {
|
||||
QofBook * book;
|
||||
GncOwner * owner;
|
||||
QueryNew * q;
|
||||
GncOwner owner_def;
|
||||
struct _job_select_window
|
||||
{
|
||||
QofBook * book;
|
||||
GncOwner * owner;
|
||||
QueryNew * q;
|
||||
GncOwner owner_def;
|
||||
};
|
||||
|
||||
struct _job_window {
|
||||
GtkWidget * dialog;
|
||||
GtkWidget * id_entry;
|
||||
GtkWidget * cust_edit;
|
||||
GtkWidget * name_entry;
|
||||
GtkWidget * desc_entry;
|
||||
GtkWidget * active_check;
|
||||
struct _job_window
|
||||
{
|
||||
GtkWidget * dialog;
|
||||
GtkWidget * id_entry;
|
||||
GtkWidget * cust_edit;
|
||||
GtkWidget * name_entry;
|
||||
GtkWidget * desc_entry;
|
||||
GtkWidget * active_check;
|
||||
|
||||
JobDialogType dialog_type;
|
||||
GUID job_guid;
|
||||
gint component_id;
|
||||
QofBook * book;
|
||||
GncJob * created_job;
|
||||
JobDialogType dialog_type;
|
||||
GUID job_guid;
|
||||
gint component_id;
|
||||
QofBook * book;
|
||||
GncJob * created_job;
|
||||
|
||||
GncOwner owner;
|
||||
GncOwner owner;
|
||||
|
||||
};
|
||||
|
||||
static GncJob *
|
||||
jw_get_job (JobWindow *jw)
|
||||
{
|
||||
if (!jw)
|
||||
return NULL;
|
||||
if (!jw)
|
||||
return NULL;
|
||||
|
||||
return gncJobLookup (jw->book, &jw->job_guid);
|
||||
return gncJobLookup (jw->book, &jw->job_guid);
|
||||
}
|
||||
|
||||
static void gnc_ui_to_job (JobWindow *jw, GncJob *job)
|
||||
{
|
||||
gnc_suspend_gui_refresh ();
|
||||
gncJobBeginEdit (job);
|
||||
gnc_suspend_gui_refresh ();
|
||||
gncJobBeginEdit (job);
|
||||
|
||||
gncJobSetID (job, gtk_editable_get_chars (GTK_EDITABLE (jw->id_entry),
|
||||
0, -1));
|
||||
gncJobSetName (job, gtk_editable_get_chars (GTK_EDITABLE (jw->name_entry),
|
||||
0, -1));
|
||||
gncJobSetReference (job, gtk_editable_get_chars
|
||||
(GTK_EDITABLE (jw->desc_entry), 0, -1));
|
||||
gncJobSetActive (job, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
|
||||
(jw->active_check)));
|
||||
{
|
||||
GncOwner * old = gncJobGetOwner (job);
|
||||
gnc_owner_get_owner (jw->cust_edit, &(jw->owner));
|
||||
if (! gncOwnerEqual (old, &(jw->owner)))
|
||||
gncJobSetOwner (job, &(jw->owner));
|
||||
}
|
||||
gncJobSetID (job, gtk_editable_get_chars (GTK_EDITABLE (jw->id_entry),
|
||||
0, -1));
|
||||
gncJobSetName (job, gtk_editable_get_chars (GTK_EDITABLE (jw->name_entry),
|
||||
0, -1));
|
||||
gncJobSetReference (job, gtk_editable_get_chars
|
||||
(GTK_EDITABLE (jw->desc_entry), 0, -1));
|
||||
gncJobSetActive (job, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
|
||||
(jw->active_check)));
|
||||
{
|
||||
GncOwner * old = gncJobGetOwner (job);
|
||||
gnc_owner_get_owner (jw->cust_edit, &(jw->owner));
|
||||
if (! gncOwnerEqual (old, &(jw->owner)))
|
||||
gncJobSetOwner (job, &(jw->owner));
|
||||
}
|
||||
|
||||
gncJobCommitEdit (job);
|
||||
gnc_resume_gui_refresh ();
|
||||
gncJobCommitEdit (job);
|
||||
gnc_resume_gui_refresh ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_job_verify_ok (JobWindow *jw)
|
||||
{
|
||||
const char *res;
|
||||
gchar *string;
|
||||
const char *res;
|
||||
gchar *string;
|
||||
|
||||
/* Check for valid name */
|
||||
res = gtk_entry_get_text (GTK_ENTRY (jw->name_entry));
|
||||
if (safe_strcmp (res, "") == 0) {
|
||||
const char *message = _("The Job must be given a name.");
|
||||
gnc_error_dialog(jw->dialog, "%s", message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Check for owner */
|
||||
gnc_owner_get_owner (jw->cust_edit, &(jw->owner));
|
||||
res = gncOwnerGetName (&(jw->owner));
|
||||
if (res == NULL || safe_strcmp (res, "") == 0) {
|
||||
const char *message = _("You must choose an owner for this job.");
|
||||
gnc_error_dialog(jw->dialog, "%s", message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Set a valid id if one was not created */
|
||||
res = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
|
||||
if (safe_strcmp (res, "") == 0) {
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncJobNextID(jw->book));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
||||
/* Now save it off */
|
||||
{
|
||||
GncJob *job = jw_get_job (jw);
|
||||
if (job) {
|
||||
gnc_ui_to_job (jw, job);
|
||||
/* Check for valid name */
|
||||
res = gtk_entry_get_text (GTK_ENTRY (jw->name_entry));
|
||||
if (safe_strcmp (res, "") == 0)
|
||||
{
|
||||
const char *message = _("The Job must be given a name.");
|
||||
gnc_error_dialog(jw->dialog, "%s", message);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, it's been saved... Change to an editor.. */
|
||||
jw->dialog_type = EDIT_JOB;
|
||||
/* Check for owner */
|
||||
gnc_owner_get_owner (jw->cust_edit, &(jw->owner));
|
||||
res = gncOwnerGetName (&(jw->owner));
|
||||
if (res == NULL || safe_strcmp (res, "") == 0)
|
||||
{
|
||||
const char *message = _("You must choose an owner for this job.");
|
||||
gnc_error_dialog(jw->dialog, "%s", message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
/* Set a valid id if one was not created */
|
||||
res = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
|
||||
if (safe_strcmp (res, "") == 0)
|
||||
{
|
||||
string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
|
||||
gncJobNextID(jw->book));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->id_entry), string);
|
||||
g_free(string);
|
||||
}
|
||||
|
||||
/* Now save it off */
|
||||
{
|
||||
GncJob *job = jw_get_job (jw);
|
||||
if (job)
|
||||
{
|
||||
gnc_ui_to_job (jw, job);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, it's been saved... Change to an editor.. */
|
||||
jw->dialog_type = EDIT_JOB;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_job_window_ok_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
JobWindow *jw = data;
|
||||
JobWindow *jw = data;
|
||||
|
||||
/* Make sure this is ok */
|
||||
if (!gnc_job_verify_ok (jw))
|
||||
return;
|
||||
/* Make sure this is ok */
|
||||
if (!gnc_job_verify_ok (jw))
|
||||
return;
|
||||
|
||||
/* Now save off the job so we can return it */
|
||||
jw->created_job = jw_get_job (jw);
|
||||
jw->job_guid = *xaccGUIDNULL ();
|
||||
/* Now save off the job so we can return it */
|
||||
jw->created_job = jw_get_job (jw);
|
||||
jw->job_guid = *xaccGUIDNULL ();
|
||||
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_job_window_cancel_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
JobWindow *jw = data;
|
||||
JobWindow *jw = data;
|
||||
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_job_window_help_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gnc_gnome_help(HF_HELP, HL_USAGE);
|
||||
gnc_gnome_help(HF_HELP, HL_USAGE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_job_window_destroy_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
JobWindow *jw = data;
|
||||
GncJob *job = jw_get_job (jw);
|
||||
JobWindow *jw = data;
|
||||
GncJob *job = jw_get_job (jw);
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
if (jw->dialog_type == NEW_JOB && job != NULL) {
|
||||
gncJobBeginEdit (job);
|
||||
gncJobDestroy (job);
|
||||
jw->job_guid = *xaccGUIDNULL ();
|
||||
}
|
||||
if (jw->dialog_type == NEW_JOB && job != NULL)
|
||||
{
|
||||
gncJobBeginEdit (job);
|
||||
gncJobDestroy (job);
|
||||
jw->job_guid = *xaccGUIDNULL ();
|
||||
}
|
||||
|
||||
gnc_unregister_gui_component (jw->component_id);
|
||||
gnc_resume_gui_refresh ();
|
||||
gnc_unregister_gui_component (jw->component_id);
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
g_free (jw);
|
||||
g_free (jw);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_job_name_changed_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
JobWindow *jw = data;
|
||||
char *fullname, *title;
|
||||
const char *name, *id;
|
||||
JobWindow *jw = data;
|
||||
char *fullname, *title;
|
||||
const char *name, *id;
|
||||
|
||||
if (!jw)
|
||||
return;
|
||||
if (!jw)
|
||||
return;
|
||||
|
||||
name = gtk_entry_get_text (GTK_ENTRY (jw->name_entry));
|
||||
if (!name || *name == '\0')
|
||||
name = _("<No name>");
|
||||
name = gtk_entry_get_text (GTK_ENTRY (jw->name_entry));
|
||||
if (!name || *name == '\0')
|
||||
name = _("<No name>");
|
||||
|
||||
id = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
|
||||
id = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
|
||||
|
||||
fullname = g_strconcat (name, " (", id, ")", (char *)NULL);
|
||||
fullname = g_strconcat (name, " (", id, ")", (char *)NULL);
|
||||
|
||||
if (jw->dialog_type == EDIT_JOB)
|
||||
title = g_strconcat (_("Edit Job"), " - ", fullname, (char *)NULL);
|
||||
else
|
||||
title = g_strconcat (_("New Job"), " - ", fullname, (char *)NULL);
|
||||
if (jw->dialog_type == EDIT_JOB)
|
||||
title = g_strconcat (_("Edit Job"), " - ", fullname, (char *)NULL);
|
||||
else
|
||||
title = g_strconcat (_("New Job"), " - ", fullname, (char *)NULL);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (jw->dialog), title);
|
||||
gtk_window_set_title (GTK_WINDOW (jw->dialog), title);
|
||||
|
||||
g_free (fullname);
|
||||
g_free (title);
|
||||
g_free (fullname);
|
||||
g_free (title);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_job_window_close_handler (gpointer user_data)
|
||||
{
|
||||
JobWindow *jw = user_data;
|
||||
JobWindow *jw = user_data;
|
||||
|
||||
gtk_widget_destroy (jw->dialog);
|
||||
jw->dialog = NULL;
|
||||
gtk_widget_destroy (jw->dialog);
|
||||
jw->dialog = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_job_window_refresh_handler (GHashTable *changes, gpointer user_data)
|
||||
{
|
||||
JobWindow *jw = user_data;
|
||||
const EventInfo *info;
|
||||
GncJob *job = jw_get_job (jw);
|
||||
JobWindow *jw = user_data;
|
||||
const EventInfo *info;
|
||||
GncJob *job = jw_get_job (jw);
|
||||
|
||||
/* If there isn't a job behind us, close down */
|
||||
if (!job) {
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Next, close if this is a destroy event */
|
||||
if (changes) {
|
||||
info = gnc_gui_get_entity_events (changes, &jw->job_guid);
|
||||
if (info && (info->event_mask & QOF_EVENT_DESTROY)) {
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
return;
|
||||
/* If there isn't a job behind us, close down */
|
||||
if (!job)
|
||||
{
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Next, close if this is a destroy event */
|
||||
if (changes)
|
||||
{
|
||||
info = gnc_gui_get_entity_events (changes, &jw->job_guid);
|
||||
if (info && (info->event_mask & QOF_EVENT_DESTROY))
|
||||
{
|
||||
gnc_close_gui_component (jw->component_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
find_handler (gpointer find_data, gpointer user_data)
|
||||
{
|
||||
const GUID *job_guid = find_data;
|
||||
JobWindow *jw = user_data;
|
||||
const GUID *job_guid = find_data;
|
||||
JobWindow *jw = user_data;
|
||||
|
||||
return(jw && guid_equal(&jw->job_guid, job_guid));
|
||||
return(jw && guid_equal(&jw->job_guid, job_guid));
|
||||
}
|
||||
|
||||
static JobWindow *
|
||||
gnc_job_new_window (QofBook *bookp, GncOwner *owner, GncJob *job)
|
||||
{
|
||||
JobWindow *jw;
|
||||
GladeXML *xml;
|
||||
GtkWidget *owner_box, *owner_label;
|
||||
JobWindow *jw;
|
||||
GladeXML *xml;
|
||||
GtkWidget *owner_box, *owner_label;
|
||||
|
||||
/*
|
||||
* Find an existing window for this job. If found, bring it to
|
||||
* the front.
|
||||
*/
|
||||
if (job) {
|
||||
GUID job_guid;
|
||||
/*
|
||||
* Find an existing window for this job. If found, bring it to
|
||||
* the front.
|
||||
*/
|
||||
if (job)
|
||||
{
|
||||
GUID job_guid;
|
||||
|
||||
job_guid = *gncJobGetGUID (job);
|
||||
jw = gnc_find_first_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
|
||||
find_handler, &job_guid);
|
||||
if (jw) {
|
||||
gtk_window_present (GTK_WINDOW(jw->dialog));
|
||||
return(jw);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* No existing job window found. Build a new one.
|
||||
*/
|
||||
jw = g_new0 (JobWindow, 1);
|
||||
jw->book = bookp;
|
||||
gncOwnerCopy (owner, &(jw->owner)); /* save it off now, we know it's valid */
|
||||
|
||||
/* Load the XML */
|
||||
xml = gnc_glade_xml_new ("job.glade", "Job Dialog");
|
||||
|
||||
/* Find the dialog */
|
||||
jw->dialog = glade_xml_get_widget (xml, "Job Dialog");
|
||||
g_object_set_data (G_OBJECT (jw->dialog), "dialog_info", jw);
|
||||
|
||||
/* Get entry points */
|
||||
jw->id_entry = glade_xml_get_widget (xml, "id_entry");
|
||||
jw->name_entry = glade_xml_get_widget (xml, "name_entry");
|
||||
jw->desc_entry = glade_xml_get_widget (xml, "desc_entry");
|
||||
jw->active_check = glade_xml_get_widget (xml, "active_check");
|
||||
|
||||
owner_box = glade_xml_get_widget (xml, "customer_hbox");
|
||||
owner_label = glade_xml_get_widget (xml, "owner_label");
|
||||
|
||||
/* Setup signals */
|
||||
glade_xml_signal_autoconnect_full( xml,
|
||||
gnc_glade_autoconnect_full_func,
|
||||
jw);
|
||||
/* Set initial entries */
|
||||
if (job != NULL) {
|
||||
jw->job_guid = *gncJobGetGUID (job);
|
||||
|
||||
jw->dialog_type = EDIT_JOB;
|
||||
jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->id_entry), gncJobGetID (job));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->name_entry), gncJobGetName (job));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->desc_entry), gncJobGetReference (job));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (jw->active_check),
|
||||
gncJobGetActive (job));
|
||||
|
||||
jw->component_id = gnc_register_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
|
||||
gnc_job_window_refresh_handler,
|
||||
gnc_job_window_close_handler,
|
||||
jw);
|
||||
} else {
|
||||
job = gncJobCreate (bookp);
|
||||
gncJobSetOwner (job, owner);
|
||||
jw->job_guid = *gncJobGetGUID (job);
|
||||
|
||||
jw->dialog_type = NEW_JOB;
|
||||
|
||||
/* If we are passed a real owner, don't allow the user to change it */
|
||||
if (owner->owner.undefined) {
|
||||
jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
} else {
|
||||
jw->cust_edit = gnc_owner_select_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
job_guid = *gncJobGetGUID (job);
|
||||
jw = gnc_find_first_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
|
||||
find_handler, &job_guid);
|
||||
if (jw)
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW(jw->dialog));
|
||||
return(jw);
|
||||
}
|
||||
}
|
||||
|
||||
jw->component_id = gnc_register_gui_component (DIALOG_NEW_JOB_CM_CLASS,
|
||||
gnc_job_window_refresh_handler,
|
||||
gnc_job_window_close_handler,
|
||||
jw);
|
||||
}
|
||||
/*
|
||||
* No existing job window found. Build a new one.
|
||||
*/
|
||||
jw = g_new0 (JobWindow, 1);
|
||||
jw->book = bookp;
|
||||
gncOwnerCopy (owner, &(jw->owner)); /* save it off now, we know it's valid */
|
||||
|
||||
gnc_job_name_changed_cb (NULL, jw);
|
||||
gnc_gui_component_watch_entity_type (jw->component_id,
|
||||
GNC_JOB_MODULE_NAME,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
/* Load the XML */
|
||||
xml = gnc_glade_xml_new ("job.glade", "Job Dialog");
|
||||
|
||||
gtk_widget_show_all (jw->dialog);
|
||||
/* Find the dialog */
|
||||
jw->dialog = glade_xml_get_widget (xml, "Job Dialog");
|
||||
g_object_set_data (G_OBJECT (jw->dialog), "dialog_info", jw);
|
||||
|
||||
return jw;
|
||||
/* Get entry points */
|
||||
jw->id_entry = glade_xml_get_widget (xml, "id_entry");
|
||||
jw->name_entry = glade_xml_get_widget (xml, "name_entry");
|
||||
jw->desc_entry = glade_xml_get_widget (xml, "desc_entry");
|
||||
jw->active_check = glade_xml_get_widget (xml, "active_check");
|
||||
|
||||
owner_box = glade_xml_get_widget (xml, "customer_hbox");
|
||||
owner_label = glade_xml_get_widget (xml, "owner_label");
|
||||
|
||||
/* Setup signals */
|
||||
glade_xml_signal_autoconnect_full( xml,
|
||||
gnc_glade_autoconnect_full_func,
|
||||
jw);
|
||||
/* Set initial entries */
|
||||
if (job != NULL)
|
||||
{
|
||||
jw->job_guid = *gncJobGetGUID (job);
|
||||
|
||||
jw->dialog_type = EDIT_JOB;
|
||||
jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->id_entry), gncJobGetID (job));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->name_entry), gncJobGetName (job));
|
||||
gtk_entry_set_text (GTK_ENTRY (jw->desc_entry), gncJobGetReference (job));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (jw->active_check),
|
||||
gncJobGetActive (job));
|
||||
|
||||
jw->component_id = gnc_register_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
|
||||
gnc_job_window_refresh_handler,
|
||||
gnc_job_window_close_handler,
|
||||
jw);
|
||||
}
|
||||
else
|
||||
{
|
||||
job = gncJobCreate (bookp);
|
||||
gncJobSetOwner (job, owner);
|
||||
jw->job_guid = *gncJobGetGUID (job);
|
||||
|
||||
jw->dialog_type = NEW_JOB;
|
||||
|
||||
/* If we are passed a real owner, don't allow the user to change it */
|
||||
if (owner->owner.undefined)
|
||||
{
|
||||
jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
jw->cust_edit = gnc_owner_select_create (owner_label, owner_box,
|
||||
bookp, owner);
|
||||
}
|
||||
|
||||
jw->component_id = gnc_register_gui_component (DIALOG_NEW_JOB_CM_CLASS,
|
||||
gnc_job_window_refresh_handler,
|
||||
gnc_job_window_close_handler,
|
||||
jw);
|
||||
}
|
||||
|
||||
gnc_job_name_changed_cb (NULL, jw);
|
||||
gnc_gui_component_watch_entity_type (jw->component_id,
|
||||
GNC_JOB_MODULE_NAME,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
|
||||
gtk_widget_show_all (jw->dialog);
|
||||
|
||||
return jw;
|
||||
}
|
||||
|
||||
GncJob *
|
||||
gnc_ui_job_new_return_handle (GncOwner *owner, QofBook *book)
|
||||
{
|
||||
JobWindow *jw;
|
||||
if (!book) return NULL;
|
||||
jw = gnc_ui_job_new (owner, book);
|
||||
return jw_get_job (jw);
|
||||
JobWindow *jw;
|
||||
if (!book) return NULL;
|
||||
jw = gnc_ui_job_new (owner, book);
|
||||
return jw_get_job (jw);
|
||||
}
|
||||
|
||||
JobWindow *
|
||||
gnc_ui_job_new (GncOwner *ownerp, QofBook *bookp)
|
||||
{
|
||||
JobWindow *jw;
|
||||
GncOwner owner;
|
||||
JobWindow *jw;
|
||||
GncOwner owner;
|
||||
|
||||
/* Make sure required options exist */
|
||||
if (!bookp) return NULL;
|
||||
/* Make sure required options exist */
|
||||
if (!bookp) return NULL;
|
||||
|
||||
if (ownerp) {
|
||||
g_return_val_if_fail ((gncOwnerGetType (ownerp) == GNC_OWNER_CUSTOMER) ||
|
||||
(gncOwnerGetType (ownerp) == GNC_OWNER_VENDOR),
|
||||
NULL);
|
||||
gncOwnerCopy (ownerp, &owner);
|
||||
} else
|
||||
gncOwnerInitCustomer (&owner, NULL); /* XXX */
|
||||
if (ownerp)
|
||||
{
|
||||
g_return_val_if_fail ((gncOwnerGetType (ownerp) == GNC_OWNER_CUSTOMER) ||
|
||||
(gncOwnerGetType (ownerp) == GNC_OWNER_VENDOR),
|
||||
NULL);
|
||||
gncOwnerCopy (ownerp, &owner);
|
||||
}
|
||||
else
|
||||
gncOwnerInitCustomer (&owner, NULL); /* XXX */
|
||||
|
||||
jw = gnc_job_new_window (bookp, &owner, NULL);
|
||||
return jw;
|
||||
jw = gnc_job_new_window (bookp, &owner, NULL);
|
||||
return jw;
|
||||
}
|
||||
|
||||
JobWindow *
|
||||
gnc_ui_job_edit (GncJob *job)
|
||||
{
|
||||
JobWindow *jw;
|
||||
JobWindow *jw;
|
||||
|
||||
if (!job) return NULL;
|
||||
if (!job) return NULL;
|
||||
|
||||
jw = gnc_job_new_window (gncJobGetBook(job), gncJobGetOwner(job), job);
|
||||
return jw;
|
||||
jw = gnc_job_new_window (gncJobGetBook(job), gncJobGetOwner(job), job);
|
||||
return jw;
|
||||
}
|
||||
|
||||
/* Search functionality */
|
||||
@@ -431,166 +451,172 @@ gnc_ui_job_edit (GncJob *job)
|
||||
static void
|
||||
edit_job_cb (gpointer *job_p, gpointer user_data)
|
||||
{
|
||||
GncJob *job;
|
||||
GncJob *job;
|
||||
|
||||
g_return_if_fail (job_p && user_data);
|
||||
g_return_if_fail (job_p && user_data);
|
||||
|
||||
job = *job_p;
|
||||
job = *job_p;
|
||||
|
||||
if (!job)
|
||||
return;
|
||||
if (!job)
|
||||
return;
|
||||
|
||||
gnc_ui_job_edit (job);
|
||||
gnc_ui_job_edit (job);
|
||||
}
|
||||
|
||||
static void
|
||||
invoice_job_cb (gpointer *job_p, gpointer user_data)
|
||||
{
|
||||
struct _job_select_window * sw = user_data;
|
||||
GncJob *job;
|
||||
GncOwner owner;
|
||||
struct _job_select_window * sw = user_data;
|
||||
GncJob *job;
|
||||
GncOwner owner;
|
||||
|
||||
g_return_if_fail (job_p && user_data);
|
||||
g_return_if_fail (job_p && user_data);
|
||||
|
||||
job = *job_p;
|
||||
if (!job)
|
||||
return;
|
||||
job = *job_p;
|
||||
if (!job)
|
||||
return;
|
||||
|
||||
gncOwnerInitJob (&owner, job);
|
||||
gnc_invoice_search (NULL, &owner, sw->book);
|
||||
gncOwnerInitJob (&owner, job);
|
||||
gnc_invoice_search (NULL, &owner, sw->book);
|
||||
}
|
||||
|
||||
static void
|
||||
payment_job_cb (gpointer *job_p, gpointer user_data)
|
||||
{
|
||||
struct _job_select_window *sw = user_data;
|
||||
GncOwner owner;
|
||||
GncJob *job;
|
||||
struct _job_select_window *sw = user_data;
|
||||
GncOwner owner;
|
||||
GncJob *job;
|
||||
|
||||
g_return_if_fail (job_p && user_data);
|
||||
g_return_if_fail (job_p && user_data);
|
||||
|
||||
job = *job_p;
|
||||
job = *job_p;
|
||||
|
||||
if (!job)
|
||||
if (!job)
|
||||
return;
|
||||
|
||||
gncOwnerInitJob (&owner, job);
|
||||
gnc_ui_payment_new (&owner, sw->book);
|
||||
return;
|
||||
|
||||
gncOwnerInitJob (&owner, job);
|
||||
gnc_ui_payment_new (&owner, sw->book);
|
||||
return;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
new_job_cb (gpointer user_data)
|
||||
{
|
||||
struct _job_select_window *sw = user_data;
|
||||
JobWindow *jw;
|
||||
|
||||
g_return_val_if_fail (user_data, NULL);
|
||||
struct _job_select_window *sw = user_data;
|
||||
JobWindow *jw;
|
||||
|
||||
jw = gnc_ui_job_new (sw->owner, sw->book);
|
||||
return jw_get_job (jw);
|
||||
g_return_val_if_fail (user_data, NULL);
|
||||
|
||||
jw = gnc_ui_job_new (sw->owner, sw->book);
|
||||
return jw_get_job (jw);
|
||||
}
|
||||
|
||||
static void
|
||||
free_userdata_cb (gpointer user_data)
|
||||
{
|
||||
struct _job_select_window *sw = user_data;
|
||||
struct _job_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_job_search (GncJob *start, GncOwner *owner, QofBook *book)
|
||||
{
|
||||
QueryNew *q, *q2 = NULL;
|
||||
GNCIdType type = GNC_JOB_MODULE_NAME;
|
||||
struct _job_select_window *sw;
|
||||
static GList *params = NULL;
|
||||
static GList *columns = NULL;
|
||||
static GNCSearchCallbackButton buttons[] = {
|
||||
{ N_("View/Edit Job"), edit_job_cb},
|
||||
{ N_("View Invoices"), invoice_job_cb},
|
||||
{ N_("Process Payment"), payment_job_cb},
|
||||
{ NULL },
|
||||
};
|
||||
QueryNew *q, *q2 = NULL;
|
||||
GNCIdType type = GNC_JOB_MODULE_NAME;
|
||||
struct _job_select_window *sw;
|
||||
static GList *params = NULL;
|
||||
static GList *columns = NULL;
|
||||
static GNCSearchCallbackButton buttons[] =
|
||||
{
|
||||
{ N_("View/Edit Job"), edit_job_cb},
|
||||
{ N_("View Invoices"), invoice_job_cb},
|
||||
{ N_("Process Payment"), payment_job_cb},
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
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, _("Owner's Name"), NULL, type,
|
||||
JOB_OWNER, OWNER_NAME, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Only Active?"), NULL, type,
|
||||
JOB_ACTIVE, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Billing ID"), NULL, type,
|
||||
JOB_REFERENCE, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Job Number"), NULL, type,
|
||||
JOB_ID, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Job Name"), NULL, type,
|
||||
JOB_NAME, NULL);
|
||||
}
|
||||
/* Build parameter list in reverse order*/
|
||||
if (params == NULL)
|
||||
{
|
||||
params = gnc_search_param_prepend (params, _("Owner's Name"), NULL, type,
|
||||
JOB_OWNER, OWNER_NAME, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Only Active?"), NULL, type,
|
||||
JOB_ACTIVE, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Billing ID"), NULL, type,
|
||||
JOB_REFERENCE, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Job Number"), NULL, type,
|
||||
JOB_ID, NULL);
|
||||
params = gnc_search_param_prepend (params, _("Job Name"), NULL, type,
|
||||
JOB_NAME, NULL);
|
||||
}
|
||||
|
||||
/* Build the column list in reverse order */
|
||||
if (columns == NULL) {
|
||||
columns = gnc_search_param_prepend (columns, _("Billing ID"), NULL, type,
|
||||
JOB_REFERENCE, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("Company"), NULL, type,
|
||||
JOB_OWNER, OWNER_NAME, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("Job Name"), NULL, type,
|
||||
JOB_NAME, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type,
|
||||
JOB_ID, NULL);
|
||||
}
|
||||
/* Build the column list in reverse order */
|
||||
if (columns == NULL)
|
||||
{
|
||||
columns = gnc_search_param_prepend (columns, _("Billing ID"), NULL, type,
|
||||
JOB_REFERENCE, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("Company"), NULL, type,
|
||||
JOB_OWNER, OWNER_NAME, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("Job Name"), NULL, type,
|
||||
JOB_NAME, NULL);
|
||||
columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type,
|
||||
JOB_ID, NULL);
|
||||
}
|
||||
|
||||
/* Build the queries */
|
||||
q = gncQueryCreateFor (type);
|
||||
gncQuerySetBook (q, book);
|
||||
/* Build the queries */
|
||||
q = gncQueryCreateFor (type);
|
||||
gncQuerySetBook (q, book);
|
||||
|
||||
/* If we have a start job but, for some reason, not an owner -- grab
|
||||
* the owner from the starting job.
|
||||
*/
|
||||
if ((!owner || !gncOwnerGetGUID (owner)) && start)
|
||||
owner = gncJobGetOwner (start);
|
||||
/* If we have a start job but, for some reason, not an owner -- grab
|
||||
* the owner from the starting job.
|
||||
*/
|
||||
if ((!owner || !gncOwnerGetGUID (owner)) && start)
|
||||
owner = gncJobGetOwner (start);
|
||||
|
||||
/* If owner is supplied, limit all searches to invoices who's owner
|
||||
* is the supplied owner! Show all invoices by this owner.
|
||||
*/
|
||||
if (owner && gncOwnerGetGUID (owner)) {
|
||||
gncQueryAddGUIDMatch (q, g_slist_prepend
|
||||
(g_slist_prepend (NULL, QUERY_PARAM_GUID),
|
||||
JOB_OWNER),
|
||||
gncOwnerGetGUID (owner), QUERY_AND);
|
||||
/* If owner is supplied, limit all searches to invoices who's owner
|
||||
* is the supplied owner! Show all invoices by this owner.
|
||||
*/
|
||||
if (owner && gncOwnerGetGUID (owner))
|
||||
{
|
||||
gncQueryAddGUIDMatch (q, g_slist_prepend
|
||||
(g_slist_prepend (NULL, QUERY_PARAM_GUID),
|
||||
JOB_OWNER),
|
||||
gncOwnerGetGUID (owner), QUERY_AND);
|
||||
|
||||
q2 = gncQueryCopy (q);
|
||||
}
|
||||
q2 = gncQueryCopy (q);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (start) {
|
||||
if (q2 == NULL)
|
||||
q2 = gncQueryCopy (q);
|
||||
if (start)
|
||||
{
|
||||
if (q2 == NULL)
|
||||
q2 = gncQueryCopy (q);
|
||||
|
||||
gncQueryAddGUIDMatch (q2, g_slist_prepend (NULL, QUERY_PARAM_GUID),
|
||||
gncJobGetGUID (start), QUERY_AND);
|
||||
}
|
||||
gncQueryAddGUIDMatch (q2, g_slist_prepend (NULL, QUERY_PARAM_GUID),
|
||||
gncJobGetGUID (start), QUERY_AND);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* launch select dialog and return the result */
|
||||
sw = g_new0 (struct _job_select_window, 1);
|
||||
/* launch select dialog and return the result */
|
||||
sw = g_new0 (struct _job_select_window, 1);
|
||||
|
||||
if (owner) {
|
||||
gncOwnerCopy (owner, &(sw->owner_def));
|
||||
sw->owner = &(sw->owner_def);
|
||||
}
|
||||
sw->book = book;
|
||||
sw->q = q;
|
||||
if (owner)
|
||||
{
|
||||
gncOwnerCopy (owner, &(sw->owner_def));
|
||||
sw->owner = &(sw->owner_def);
|
||||
}
|
||||
sw->book = book;
|
||||
sw->q = q;
|
||||
|
||||
return gnc_search_dialog_create (type, _("Find Job"),
|
||||
params, columns, q, q2, buttons, NULL,
|
||||
new_job_cb, sw, free_userdata_cb,
|
||||
GCONF_SECTION_SEARCH, NULL);
|
||||
return gnc_search_dialog_create (type, _("Find Job"),
|
||||
params, columns, q, q2, buttons, NULL,
|
||||
new_job_cb, sw, free_userdata_cb,
|
||||
GCONF_SECTION_SEARCH, NULL);
|
||||
}
|
||||
|
||||
/* Functions for widgets for job selection */
|
||||
@@ -598,25 +624,27 @@ gnc_job_search (GncJob *start, GncOwner *owner, QofBook *book)
|
||||
GNCSearchWindow *
|
||||
gnc_job_search_select (gpointer start, gpointer book)
|
||||
{
|
||||
GncJob *j = start;
|
||||
GncOwner owner, *ownerp;
|
||||
GncJob *j = start;
|
||||
GncOwner owner, *ownerp;
|
||||
|
||||
if (!book) return NULL;
|
||||
if (!book) return NULL;
|
||||
|
||||
if (j) {
|
||||
ownerp = gncJobGetOwner (j);
|
||||
gncOwnerCopy (ownerp, &owner);
|
||||
} else
|
||||
gncOwnerInitCustomer (&owner, NULL); /* XXX */
|
||||
if (j)
|
||||
{
|
||||
ownerp = gncJobGetOwner (j);
|
||||
gncOwnerCopy (ownerp, &owner);
|
||||
}
|
||||
else
|
||||
gncOwnerInitCustomer (&owner, NULL); /* XXX */
|
||||
|
||||
return gnc_job_search (start, &owner, book);
|
||||
return gnc_job_search (start, &owner, book);
|
||||
}
|
||||
|
||||
GNCSearchWindow *
|
||||
gnc_job_search_edit (gpointer start, gpointer book)
|
||||
{
|
||||
if (start)
|
||||
gnc_ui_job_edit (start);
|
||||
if (start)
|
||||
gnc_ui_job_edit (start);
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ JobWindow * gnc_ui_job_new (GncOwner *owner, QofBook *book);
|
||||
|
||||
/* Search for Jobs */
|
||||
GNCSearchWindow * gnc_job_search (GncJob *start, GncOwner *owner,
|
||||
QofBook *book);
|
||||
QofBook *book);
|
||||
|
||||
/*
|
||||
* These callbacks are for use with the gnc_general_search widget
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,7 @@ OrderWindow * gnc_ui_order_new (GncOwner *owner, QofBook *book);
|
||||
|
||||
/* Search for orders */
|
||||
GNCSearchWindow * gnc_order_search (GncOrder *start, GncOwner *owner,
|
||||
QofBook *book);
|
||||
QofBook *book);
|
||||
|
||||
/*
|
||||
* These callbacks are for use with the gnc_general_search widget
|
||||
|
||||
@@ -50,24 +50,25 @@
|
||||
#define DIALOG_PAYMENT_CUSTOMER_CM_CLASS "customer-payment-dialog"
|
||||
#define DIALOG_PAYMENT_VENDOR_CM_CLASS "vendor-payment-dialog"
|
||||
|
||||
struct _payment_window {
|
||||
GtkWidget * dialog;
|
||||
struct _payment_window
|
||||
{
|
||||
GtkWidget * dialog;
|
||||
|
||||
GtkWidget * num_entry;
|
||||
GtkWidget * memo_entry;
|
||||
GtkWidget * post_combo;
|
||||
GtkWidget * owner_choice;
|
||||
GtkWidget * invoice_choice;
|
||||
GtkWidget * amount_edit;
|
||||
GtkWidget * date_edit;
|
||||
GtkWidget * acct_tree;
|
||||
GtkWidget * num_entry;
|
||||
GtkWidget * memo_entry;
|
||||
GtkWidget * post_combo;
|
||||
GtkWidget * owner_choice;
|
||||
GtkWidget * invoice_choice;
|
||||
GtkWidget * amount_edit;
|
||||
GtkWidget * date_edit;
|
||||
GtkWidget * acct_tree;
|
||||
|
||||
gint component_id;
|
||||
QofBook * book;
|
||||
GncOwner owner;
|
||||
GncInvoice * invoice;
|
||||
GList * acct_types;
|
||||
GList * acct_commodities;
|
||||
gint component_id;
|
||||
QofBook * book;
|
||||
GncOwner owner;
|
||||
GncInvoice * invoice;
|
||||
GList * acct_types;
|
||||
GList * acct_commodities;
|
||||
};
|
||||
|
||||
|
||||
@@ -75,518 +76,535 @@ void gnc_payment_ok_cb (GtkWidget *widget, gpointer data);
|
||||
void gnc_payment_cancel_cb (GtkWidget *widget, gpointer data);
|
||||
void gnc_payment_window_destroy_cb (GtkWidget *widget, gpointer data);
|
||||
void gnc_payment_acct_tree_row_activated_cb (GtkWidget *widget, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, PaymentWindow *pw);
|
||||
GtkTreeViewColumn *column, PaymentWindow *pw);
|
||||
|
||||
|
||||
static void
|
||||
gnc_payment_window_refresh_handler (GHashTable *changes, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
PaymentWindow *pw = data;
|
||||
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_window_close_handler (gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
PaymentWindow *pw = data;
|
||||
|
||||
if (pw)
|
||||
gtk_widget_destroy (pw->dialog);
|
||||
if (pw)
|
||||
gtk_widget_destroy (pw->dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_dialog_invoice_changed(PaymentWindow *pw)
|
||||
{
|
||||
GNCLot *lot;
|
||||
gnc_numeric val;
|
||||
GNCLot *lot;
|
||||
gnc_numeric val;
|
||||
|
||||
/* Set the payment amount in the dialog */
|
||||
if (pw->invoice) {
|
||||
lot = gncInvoiceGetPostedLot (pw->invoice);
|
||||
val = gnc_numeric_abs (gnc_lot_get_balance (lot));
|
||||
} else {
|
||||
val = gnc_numeric_zero();
|
||||
}
|
||||
/* Set the payment amount in the dialog */
|
||||
if (pw->invoice)
|
||||
{
|
||||
lot = gncInvoiceGetPostedLot (pw->invoice);
|
||||
val = gnc_numeric_abs (gnc_lot_get_balance (lot));
|
||||
}
|
||||
else
|
||||
{
|
||||
val = gnc_numeric_zero();
|
||||
}
|
||||
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_edit), val);
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_edit), val);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_dialog_owner_changed(PaymentWindow *pw)
|
||||
{
|
||||
Account *last_acct=NULL;
|
||||
GUID *guid=NULL;
|
||||
KvpValue* value;
|
||||
KvpFrame* slots;
|
||||
Account *last_acct = NULL;
|
||||
GUID *guid = NULL;
|
||||
KvpValue* value;
|
||||
KvpFrame* slots;
|
||||
|
||||
/* If the owner changed, the invoice selection is invalid */
|
||||
pw->invoice = NULL;
|
||||
gnc_invoice_set_owner(pw->invoice_choice, &pw->owner);
|
||||
/* note that set_owner implies ...set_invoice(...,NULL); */
|
||||
/* If the owner changed, the invoice selection is invalid */
|
||||
pw->invoice = NULL;
|
||||
gnc_invoice_set_owner(pw->invoice_choice, &pw->owner);
|
||||
/* note that set_owner implies ...set_invoice(...,NULL); */
|
||||
|
||||
/* in case we don't get the callback */
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
/* in case we don't get the callback */
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
|
||||
/* XXX: We should set the sensitive flag on the invoice_choice
|
||||
* based on whether 'owner' is NULL or not...
|
||||
*/
|
||||
/* XXX: We should set the sensitive flag on the invoice_choice
|
||||
* based on whether 'owner' is NULL or not...
|
||||
*/
|
||||
|
||||
/* Now handle the account tree */
|
||||
slots = gncOwnerGetSlots(&pw->owner);
|
||||
if (slots)
|
||||
{
|
||||
value = kvp_frame_get_slot_path(slots, "payment", "last_acct", NULL);
|
||||
if (value)
|
||||
/* Now handle the account tree */
|
||||
slots = gncOwnerGetSlots(&pw->owner);
|
||||
if (slots)
|
||||
{
|
||||
guid = kvp_value_get_guid(value);
|
||||
value = kvp_frame_get_slot_path(slots, "payment", "last_acct", NULL);
|
||||
if (value)
|
||||
{
|
||||
guid = kvp_value_get_guid(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* refresh the post and acc available accounts, but cleanup first */
|
||||
if (pw->acct_types)
|
||||
{
|
||||
g_list_free(pw->acct_types);
|
||||
pw->acct_types = NULL;
|
||||
}
|
||||
/* refresh the post and acc available accounts, but cleanup first */
|
||||
if (pw->acct_types)
|
||||
{
|
||||
g_list_free(pw->acct_types);
|
||||
pw->acct_types = NULL;
|
||||
}
|
||||
|
||||
if (pw->acct_commodities)
|
||||
{
|
||||
g_list_free(pw->acct_commodities);
|
||||
pw->acct_commodities = NULL;
|
||||
}
|
||||
if (pw->acct_commodities)
|
||||
{
|
||||
g_list_free(pw->acct_commodities);
|
||||
pw->acct_commodities = NULL;
|
||||
}
|
||||
|
||||
pw->acct_types = gnc_business_account_types(&pw->owner);
|
||||
pw->acct_commodities = gnc_business_commodities (&pw->owner);
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
pw->acct_types = gnc_business_account_types(&pw->owner);
|
||||
pw->acct_commodities = gnc_business_commodities (&pw->owner);
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
|
||||
if (guid)
|
||||
{
|
||||
last_acct = xaccAccountLookup(guid, pw->book);
|
||||
}
|
||||
if (guid)
|
||||
{
|
||||
last_acct = xaccAccountLookup(guid, pw->book);
|
||||
}
|
||||
|
||||
/* Set the last-used transfer account */
|
||||
if (last_acct) {
|
||||
gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree),
|
||||
last_acct);
|
||||
}
|
||||
/* Set the last-used transfer account */
|
||||
if (last_acct)
|
||||
{
|
||||
gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree),
|
||||
last_acct);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_payment_dialog_remember_account(PaymentWindow *pw, Account *acc)
|
||||
{
|
||||
KvpValue* value;
|
||||
KvpFrame* slots = gncOwnerGetSlots(&pw->owner);
|
||||
KvpValue* value;
|
||||
KvpFrame* slots = gncOwnerGetSlots(&pw->owner);
|
||||
|
||||
if (!acc) return;
|
||||
if (!slots) return;
|
||||
if (!acc) return;
|
||||
if (!slots) return;
|
||||
|
||||
value = kvp_value_new_guid(xaccAccountGetGUID(acc));
|
||||
if (!value) return;
|
||||
|
||||
kvp_frame_set_slot_path(slots, value, "payment", "last_acct", NULL);
|
||||
kvp_value_delete(value);
|
||||
value = kvp_value_new_guid(xaccAccountGetGUID(acc));
|
||||
if (!value) return;
|
||||
|
||||
/* XXX: FIXME: Need a commit_edit here to save the data! */
|
||||
kvp_frame_set_slot_path(slots, value, "payment", "last_acct", NULL);
|
||||
kvp_value_delete(value);
|
||||
|
||||
/* XXX: FIXME: Need a commit_edit here to save the data! */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnc_payment_set_owner (PaymentWindow *pw, GncOwner *owner)
|
||||
{
|
||||
gnc_owner_set_owner (pw->owner_choice, owner);
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
gnc_owner_set_owner (pw->owner_choice, owner);
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
}
|
||||
|
||||
static int
|
||||
gnc_payment_dialog_owner_changed_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
GncOwner owner;
|
||||
PaymentWindow *pw = data;
|
||||
GncOwner owner;
|
||||
|
||||
if (!pw) return FALSE;
|
||||
if (!pw) return FALSE;
|
||||
|
||||
gncOwnerCopy (&(pw->owner), &owner);
|
||||
gnc_owner_get_owner (pw->owner_choice, &owner);
|
||||
gncOwnerCopy (&(pw->owner), &owner);
|
||||
gnc_owner_get_owner (pw->owner_choice, &owner);
|
||||
|
||||
/* If this owner really changed, then reset ourselves */
|
||||
if (!gncOwnerEqual (&owner, &(pw->owner))) {
|
||||
gncOwnerCopy (&owner, &(pw->owner));
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
}
|
||||
/* If this owner really changed, then reset ourselves */
|
||||
if (!gncOwnerEqual (&owner, &(pw->owner)))
|
||||
{
|
||||
gncOwnerCopy (&owner, &(pw->owner));
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
gnc_payment_dialog_invoice_changed_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
GncInvoice *invoice;
|
||||
PaymentWindow *pw = data;
|
||||
GncInvoice *invoice;
|
||||
|
||||
if (!pw) return FALSE;
|
||||
if (!pw) return FALSE;
|
||||
|
||||
invoice = gnc_invoice_get_invoice (pw->invoice_choice);
|
||||
invoice = gnc_invoice_get_invoice (pw->invoice_choice);
|
||||
|
||||
/* If this invoice really changed, then reset ourselves */
|
||||
if (invoice != pw->invoice) {
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
}
|
||||
/* If this invoice really changed, then reset ourselves */
|
||||
if (invoice != pw->invoice)
|
||||
{
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_payment_ok_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
const char *text;
|
||||
Account *post, *acc;
|
||||
gnc_numeric amount;
|
||||
PaymentWindow *pw = data;
|
||||
const char *text;
|
||||
Account *post, *acc;
|
||||
gnc_numeric amount;
|
||||
|
||||
if (!pw)
|
||||
return;
|
||||
if (!pw)
|
||||
return;
|
||||
|
||||
/* Verify the amount is non-zero */
|
||||
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (pw->amount_edit));
|
||||
if (gnc_numeric_check (amount) || !gnc_numeric_positive_p (amount)) {
|
||||
text = _("You must enter the amount of the payment. "
|
||||
"The payment amount must be greater than zero.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Verify the user has selected an owner */
|
||||
gnc_owner_get_owner (pw->owner_choice, &(pw->owner));
|
||||
if (pw->owner.owner.undefined == NULL) {
|
||||
text = _("You must select a company for payment processing.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Verify the user has selected a transfer account */
|
||||
acc = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(pw->acct_tree));
|
||||
if (!acc) {
|
||||
text = _("You must select a transfer account from the account tree.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Verify the "post" account */
|
||||
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pw->post_combo));
|
||||
if (!text || safe_strcmp (text, "") == 0) {
|
||||
text = _("You must enter an account name for posting.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
post = gnc_account_lookup_by_full_name (gnc_book_get_root_account (pw->book), text);
|
||||
|
||||
if (!post) {
|
||||
char *msg = g_strdup_printf (
|
||||
_("Your selected post account, %s, does not exist"),
|
||||
text);
|
||||
gnc_error_dialog (pw->dialog, "%s", msg);
|
||||
g_free (msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ok, now post the damn thing */
|
||||
gnc_suspend_gui_refresh ();
|
||||
{
|
||||
const char *memo, *num;
|
||||
Timespec date;
|
||||
gnc_numeric exch = gnc_numeric_create(1,1); //default to "one to one" rate
|
||||
|
||||
/* Obtain all our ancillary information */
|
||||
memo = gtk_entry_get_text (GTK_ENTRY (pw->memo_entry));
|
||||
num = gtk_entry_get_text (GTK_ENTRY (pw->num_entry));
|
||||
date = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (pw->date_edit));
|
||||
|
||||
/* If the 'acc' account and the post account don't have the same
|
||||
currency, we need to get the user to specify the exchange rate */
|
||||
if (!gnc_commodity_equal(xaccAccountGetCommodity(acc), xaccAccountGetCommodity(post)))
|
||||
/* Verify the amount is non-zero */
|
||||
amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (pw->amount_edit));
|
||||
if (gnc_numeric_check (amount) || !gnc_numeric_positive_p (amount))
|
||||
{
|
||||
XferDialog* xfer;
|
||||
|
||||
text = _("The transfer and post accounts are associated with different currencies. Please specify the conversion rate.");
|
||||
|
||||
xfer = gnc_xfer_dialog(pw->dialog, acc);
|
||||
gnc_info_dialog(pw->dialog, "%s", text);
|
||||
|
||||
gnc_xfer_dialog_select_to_account(xfer,post);
|
||||
gnc_xfer_dialog_set_amount(xfer, amount);
|
||||
|
||||
/* All we want is the exchange rate so prevent the user from thinking
|
||||
it makes sense to mess with other stuff */
|
||||
gnc_xfer_dialog_set_from_show_button_active(xfer, FALSE);
|
||||
gnc_xfer_dialog_set_to_show_button_active(xfer, FALSE);
|
||||
gnc_xfer_dialog_hide_from_account_tree(xfer);
|
||||
gnc_xfer_dialog_hide_to_account_tree(xfer);
|
||||
gnc_xfer_dialog_is_exchange_dialog(xfer, &exch);
|
||||
gnc_xfer_dialog_run_until_done(xfer);
|
||||
text = _("You must enter the amount of the payment. "
|
||||
"The payment amount must be greater than zero.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now apply the payment */
|
||||
gncOwnerApplyPayment (&pw->owner, pw->invoice,
|
||||
post, acc, amount, exch, date, memo, num);
|
||||
|
||||
}
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
/* Save the transfer account, acc */
|
||||
gnc_payment_dialog_remember_account(pw, acc);
|
||||
/* Verify the user has selected an owner */
|
||||
gnc_owner_get_owner (pw->owner_choice, &(pw->owner));
|
||||
if (pw->owner.owner.undefined == NULL)
|
||||
{
|
||||
text = _("You must select a company for payment processing.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
gnc_ui_payment_window_destroy (pw);
|
||||
/* Verify the user has selected a transfer account */
|
||||
acc = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(pw->acct_tree));
|
||||
if (!acc)
|
||||
{
|
||||
text = _("You must select a transfer account from the account tree.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Verify the "post" account */
|
||||
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pw->post_combo));
|
||||
if (!text || safe_strcmp (text, "") == 0)
|
||||
{
|
||||
text = _("You must enter an account name for posting.");
|
||||
gnc_error_dialog (pw->dialog, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
post = gnc_account_lookup_by_full_name (gnc_book_get_root_account (pw->book), text);
|
||||
|
||||
if (!post)
|
||||
{
|
||||
char *msg = g_strdup_printf (
|
||||
_("Your selected post account, %s, does not exist"),
|
||||
text);
|
||||
gnc_error_dialog (pw->dialog, "%s", msg);
|
||||
g_free (msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ok, now post the damn thing */
|
||||
gnc_suspend_gui_refresh ();
|
||||
{
|
||||
const char *memo, *num;
|
||||
Timespec date;
|
||||
gnc_numeric exch = gnc_numeric_create(1, 1); //default to "one to one" rate
|
||||
|
||||
/* Obtain all our ancillary information */
|
||||
memo = gtk_entry_get_text (GTK_ENTRY (pw->memo_entry));
|
||||
num = gtk_entry_get_text (GTK_ENTRY (pw->num_entry));
|
||||
date = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (pw->date_edit));
|
||||
|
||||
/* If the 'acc' account and the post account don't have the same
|
||||
currency, we need to get the user to specify the exchange rate */
|
||||
if (!gnc_commodity_equal(xaccAccountGetCommodity(acc), xaccAccountGetCommodity(post)))
|
||||
{
|
||||
XferDialog* xfer;
|
||||
|
||||
text = _("The transfer and post accounts are associated with different currencies. Please specify the conversion rate.");
|
||||
|
||||
xfer = gnc_xfer_dialog(pw->dialog, acc);
|
||||
gnc_info_dialog(pw->dialog, "%s", text);
|
||||
|
||||
gnc_xfer_dialog_select_to_account(xfer, post);
|
||||
gnc_xfer_dialog_set_amount(xfer, amount);
|
||||
|
||||
/* All we want is the exchange rate so prevent the user from thinking
|
||||
it makes sense to mess with other stuff */
|
||||
gnc_xfer_dialog_set_from_show_button_active(xfer, FALSE);
|
||||
gnc_xfer_dialog_set_to_show_button_active(xfer, FALSE);
|
||||
gnc_xfer_dialog_hide_from_account_tree(xfer);
|
||||
gnc_xfer_dialog_hide_to_account_tree(xfer);
|
||||
gnc_xfer_dialog_is_exchange_dialog(xfer, &exch);
|
||||
gnc_xfer_dialog_run_until_done(xfer);
|
||||
}
|
||||
|
||||
/* Now apply the payment */
|
||||
gncOwnerApplyPayment (&pw->owner, pw->invoice,
|
||||
post, acc, amount, exch, date, memo, num);
|
||||
|
||||
}
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
/* Save the transfer account, acc */
|
||||
gnc_payment_dialog_remember_account(pw, acc);
|
||||
|
||||
gnc_ui_payment_window_destroy (pw);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_payment_cancel_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
gnc_ui_payment_window_destroy (pw);
|
||||
PaymentWindow *pw = data;
|
||||
gnc_ui_payment_window_destroy (pw);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_payment_window_destroy_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
PaymentWindow *pw = data;
|
||||
PaymentWindow *pw = data;
|
||||
|
||||
if (!pw) return;
|
||||
if (!pw) return;
|
||||
|
||||
gnc_unregister_gui_component (pw->component_id);
|
||||
gnc_unregister_gui_component (pw->component_id);
|
||||
|
||||
g_list_free (pw->acct_types);
|
||||
g_list_free (pw->acct_commodities);
|
||||
g_free (pw);
|
||||
g_list_free (pw->acct_types);
|
||||
g_list_free (pw->acct_commodities);
|
||||
g_free (pw);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_payment_acct_tree_row_activated_cb (GtkWidget *widget, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, PaymentWindow *pw)
|
||||
{
|
||||
GtkTreeView *view;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeView *view;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_if_fail(widget);
|
||||
view = GTK_TREE_VIEW(widget);
|
||||
g_return_if_fail(widget);
|
||||
view = GTK_TREE_VIEW(widget);
|
||||
|
||||
model = gtk_tree_view_get_model(view);
|
||||
if (gtk_tree_model_get_iter(model, &iter, path))
|
||||
{
|
||||
if (gtk_tree_model_iter_has_child(model, &iter))
|
||||
{
|
||||
/* There are children,
|
||||
* just expand or collapse the row. */
|
||||
if (gtk_tree_view_row_expanded(view, path))
|
||||
gtk_tree_view_collapse_row(view, path);
|
||||
else
|
||||
gtk_tree_view_expand_row(view, path, FALSE);
|
||||
}
|
||||
else
|
||||
/* It's an account without any children, so click the Ok button. */
|
||||
gnc_payment_ok_cb(widget, pw);
|
||||
}
|
||||
model = gtk_tree_view_get_model(view);
|
||||
if (gtk_tree_model_get_iter(model, &iter, path))
|
||||
{
|
||||
if (gtk_tree_model_iter_has_child(model, &iter))
|
||||
{
|
||||
/* There are children,
|
||||
* just expand or collapse the row. */
|
||||
if (gtk_tree_view_row_expanded(view, path))
|
||||
gtk_tree_view_collapse_row(view, path);
|
||||
else
|
||||
gtk_tree_view_expand_row(view, path, FALSE);
|
||||
}
|
||||
else
|
||||
/* It's an account without any children, so click the Ok button. */
|
||||
gnc_payment_ok_cb(widget, pw);
|
||||
}
|
||||
}
|
||||
|
||||
/* Select the list of accounts to show in the tree */
|
||||
static void
|
||||
gnc_payment_set_account_types (GncTreeViewAccount *tree)
|
||||
{
|
||||
AccountViewInfo avi;
|
||||
int i;
|
||||
AccountViewInfo avi;
|
||||
int i;
|
||||
|
||||
gnc_tree_view_account_get_view_info (tree, &avi);
|
||||
gnc_tree_view_account_get_view_info (tree, &avi);
|
||||
|
||||
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
|
||||
switch (i) {
|
||||
case ACCT_TYPE_BANK:
|
||||
case ACCT_TYPE_CASH:
|
||||
case ACCT_TYPE_CREDIT:
|
||||
case ACCT_TYPE_ASSET:
|
||||
case ACCT_TYPE_LIABILITY:
|
||||
avi.include_type[i] = TRUE;
|
||||
break;
|
||||
default:
|
||||
avi.include_type[i] = FALSE;
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
|
||||
switch (i)
|
||||
{
|
||||
case ACCT_TYPE_BANK:
|
||||
case ACCT_TYPE_CASH:
|
||||
case ACCT_TYPE_CREDIT:
|
||||
case ACCT_TYPE_ASSET:
|
||||
case ACCT_TYPE_LIABILITY:
|
||||
avi.include_type[i] = TRUE;
|
||||
break;
|
||||
default:
|
||||
avi.include_type[i] = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
gnc_tree_view_account_set_view_info (tree, &avi);
|
||||
gnc_tree_view_account_set_view_info (tree, &avi);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
find_handler (gpointer find_data, gpointer user_data)
|
||||
{
|
||||
PaymentWindow *pw = user_data;
|
||||
PaymentWindow *pw = user_data;
|
||||
|
||||
return (pw != NULL);
|
||||
return (pw != NULL);
|
||||
}
|
||||
|
||||
static PaymentWindow *
|
||||
new_payment_window (GncOwner *owner, QofBook *book, GncInvoice *invoice)
|
||||
{
|
||||
PaymentWindow *pw;
|
||||
GladeXML *xml;
|
||||
GtkWidget *box, *label;
|
||||
char * cm_class = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER ?
|
||||
DIALOG_PAYMENT_CUSTOMER_CM_CLASS :
|
||||
DIALOG_PAYMENT_VENDOR_CM_CLASS);
|
||||
PaymentWindow *pw;
|
||||
GladeXML *xml;
|
||||
GtkWidget *box, *label;
|
||||
char * cm_class = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER ?
|
||||
DIALOG_PAYMENT_CUSTOMER_CM_CLASS :
|
||||
DIALOG_PAYMENT_VENDOR_CM_CLASS);
|
||||
|
||||
/*
|
||||
* Find an existing payment window. If found, bring it to
|
||||
* the front. If we have an actual owner, then set it in
|
||||
* the window.
|
||||
*/
|
||||
/*
|
||||
* Find an existing payment window. If found, bring it to
|
||||
* the front. If we have an actual owner, then set it in
|
||||
* the window.
|
||||
*/
|
||||
|
||||
pw = gnc_find_first_gui_component (cm_class, find_handler, NULL);
|
||||
if (pw) {
|
||||
if (owner->owner.undefined)
|
||||
gnc_payment_set_owner (pw, owner);
|
||||
pw = gnc_find_first_gui_component (cm_class, find_handler, NULL);
|
||||
if (pw)
|
||||
{
|
||||
if (owner->owner.undefined)
|
||||
gnc_payment_set_owner (pw, owner);
|
||||
|
||||
gtk_window_present (GTK_WINDOW(pw->dialog));
|
||||
return(pw);
|
||||
}
|
||||
|
||||
/* Ok, we need a new window */
|
||||
|
||||
pw = g_new0 (PaymentWindow, 1);
|
||||
pw->book = book;
|
||||
gncOwnerCopy (owner, &(pw->owner));
|
||||
|
||||
/* Compute the post-to account types */
|
||||
pw->acct_types = gnc_business_account_types (owner);
|
||||
|
||||
pw->acct_commodities = gnc_business_commodities (owner);
|
||||
|
||||
/* Open and read the XML */
|
||||
xml = gnc_glade_xml_new ("payment.glade", "Payment Dialog");
|
||||
pw->dialog = glade_xml_get_widget (xml, "Payment Dialog");
|
||||
|
||||
/* Grab the widgets and build the dialog */
|
||||
pw->num_entry = glade_xml_get_widget (xml, "num_entry");
|
||||
pw->memo_entry = glade_xml_get_widget (xml, "memo_entry");
|
||||
pw->post_combo = glade_xml_get_widget (xml, "post_combo");
|
||||
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pw->post_combo));
|
||||
|
||||
label = glade_xml_get_widget (xml, "owner_label");
|
||||
box = glade_xml_get_widget (xml, "owner_box");
|
||||
pw->owner_choice = gnc_owner_select_create (label, box, book, owner);
|
||||
|
||||
label = glade_xml_get_widget (xml, "invoice_label");
|
||||
box = glade_xml_get_widget (xml, "invoice_box");
|
||||
pw->invoice_choice = gnc_invoice_select_create (box, book, owner, invoice, label);
|
||||
|
||||
box = glade_xml_get_widget (xml, "amount_box");
|
||||
pw->amount_edit = gnc_amount_edit_new ();
|
||||
gtk_box_pack_start (GTK_BOX (box), pw->amount_edit, TRUE, TRUE, 0);
|
||||
gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_edit),
|
||||
TRUE);
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_edit), gnc_numeric_zero());
|
||||
|
||||
box = glade_xml_get_widget (xml, "date_box");
|
||||
pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (box), pw->date_edit, TRUE, TRUE, 0);
|
||||
|
||||
box = glade_xml_get_widget (xml, "acct_window");
|
||||
pw->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE));
|
||||
gtk_container_add (GTK_CONTAINER (box), pw->acct_tree);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE);
|
||||
gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree));
|
||||
|
||||
/* Set the dialog for the 'new' owner */
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
|
||||
/* Set the dialog for the 'new' invoice */
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
|
||||
/* Setup signals */
|
||||
glade_xml_signal_autoconnect_full( xml,
|
||||
gnc_glade_autoconnect_full_func,
|
||||
pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->owner_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->invoice_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_invoice_changed_cb), pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->acct_tree), "row-activated",
|
||||
G_CALLBACK (gnc_payment_acct_tree_row_activated_cb), pw);
|
||||
|
||||
/* Register with the component manager */
|
||||
pw->component_id =
|
||||
gnc_register_gui_component (cm_class,
|
||||
gnc_payment_window_refresh_handler,
|
||||
gnc_payment_window_close_handler,
|
||||
pw);
|
||||
|
||||
/* Watch for any new or changed accounts */
|
||||
gnc_gui_component_watch_entity_type (pw->component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
QOF_EVENT_CREATE | QOF_EVENT_MODIFY |
|
||||
QOF_EVENT_DESTROY);
|
||||
|
||||
/* Fill in the post_combo and account_tree widgets */
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
/* Show it all */
|
||||
gtk_widget_show_all (pw->dialog);
|
||||
|
||||
/* Warn the user if they have no valid post-to accounts */
|
||||
{
|
||||
const gchar *text;
|
||||
const char *acct_type;
|
||||
|
||||
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pw->post_combo));
|
||||
if (!text || safe_strcmp (text, "") == 0) {
|
||||
|
||||
/* XXX: I know there's only one type here */
|
||||
acct_type = xaccAccountGetTypeStr(GPOINTER_TO_INT(pw->acct_types->data));
|
||||
gnc_warning_dialog(pw->dialog,
|
||||
_("You have no valid \"Post To\" accounts. "
|
||||
"Please create an account of type \"%s\" "
|
||||
"before you continue to process this payment. "
|
||||
"Perhaps you want to create an Invoice or "
|
||||
"Bill first?"),
|
||||
acct_type);
|
||||
gtk_window_present (GTK_WINDOW(pw->dialog));
|
||||
return(pw);
|
||||
}
|
||||
}
|
||||
|
||||
return pw;
|
||||
/* Ok, we need a new window */
|
||||
|
||||
pw = g_new0 (PaymentWindow, 1);
|
||||
pw->book = book;
|
||||
gncOwnerCopy (owner, &(pw->owner));
|
||||
|
||||
/* Compute the post-to account types */
|
||||
pw->acct_types = gnc_business_account_types (owner);
|
||||
|
||||
pw->acct_commodities = gnc_business_commodities (owner);
|
||||
|
||||
/* Open and read the XML */
|
||||
xml = gnc_glade_xml_new ("payment.glade", "Payment Dialog");
|
||||
pw->dialog = glade_xml_get_widget (xml, "Payment Dialog");
|
||||
|
||||
/* Grab the widgets and build the dialog */
|
||||
pw->num_entry = glade_xml_get_widget (xml, "num_entry");
|
||||
pw->memo_entry = glade_xml_get_widget (xml, "memo_entry");
|
||||
pw->post_combo = glade_xml_get_widget (xml, "post_combo");
|
||||
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pw->post_combo));
|
||||
|
||||
label = glade_xml_get_widget (xml, "owner_label");
|
||||
box = glade_xml_get_widget (xml, "owner_box");
|
||||
pw->owner_choice = gnc_owner_select_create (label, box, book, owner);
|
||||
|
||||
label = glade_xml_get_widget (xml, "invoice_label");
|
||||
box = glade_xml_get_widget (xml, "invoice_box");
|
||||
pw->invoice_choice = gnc_invoice_select_create (box, book, owner, invoice, label);
|
||||
|
||||
box = glade_xml_get_widget (xml, "amount_box");
|
||||
pw->amount_edit = gnc_amount_edit_new ();
|
||||
gtk_box_pack_start (GTK_BOX (box), pw->amount_edit, TRUE, TRUE, 0);
|
||||
gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_edit),
|
||||
TRUE);
|
||||
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_edit), gnc_numeric_zero());
|
||||
|
||||
box = glade_xml_get_widget (xml, "date_box");
|
||||
pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE);
|
||||
gtk_box_pack_start (GTK_BOX (box), pw->date_edit, TRUE, TRUE, 0);
|
||||
|
||||
box = glade_xml_get_widget (xml, "acct_window");
|
||||
pw->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE));
|
||||
gtk_container_add (GTK_CONTAINER (box), pw->acct_tree);
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE);
|
||||
gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree));
|
||||
|
||||
/* Set the dialog for the 'new' owner */
|
||||
gnc_payment_dialog_owner_changed(pw);
|
||||
|
||||
/* Set the dialog for the 'new' invoice */
|
||||
pw->invoice = invoice;
|
||||
gnc_payment_dialog_invoice_changed(pw);
|
||||
|
||||
/* Setup signals */
|
||||
glade_xml_signal_autoconnect_full( xml,
|
||||
gnc_glade_autoconnect_full_func,
|
||||
pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->owner_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->invoice_choice), "changed",
|
||||
G_CALLBACK (gnc_payment_dialog_invoice_changed_cb), pw);
|
||||
|
||||
g_signal_connect (G_OBJECT (pw->acct_tree), "row-activated",
|
||||
G_CALLBACK (gnc_payment_acct_tree_row_activated_cb), pw);
|
||||
|
||||
/* Register with the component manager */
|
||||
pw->component_id =
|
||||
gnc_register_gui_component (cm_class,
|
||||
gnc_payment_window_refresh_handler,
|
||||
gnc_payment_window_close_handler,
|
||||
pw);
|
||||
|
||||
/* Watch for any new or changed accounts */
|
||||
gnc_gui_component_watch_entity_type (pw->component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
QOF_EVENT_CREATE | QOF_EVENT_MODIFY |
|
||||
QOF_EVENT_DESTROY);
|
||||
|
||||
/* Fill in the post_combo and account_tree widgets */
|
||||
gnc_fill_account_select_combo (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities);
|
||||
/* Show it all */
|
||||
gtk_widget_show_all (pw->dialog);
|
||||
|
||||
/* Warn the user if they have no valid post-to accounts */
|
||||
{
|
||||
const gchar *text;
|
||||
const char *acct_type;
|
||||
|
||||
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pw->post_combo));
|
||||
if (!text || safe_strcmp (text, "") == 0)
|
||||
{
|
||||
|
||||
/* XXX: I know there's only one type here */
|
||||
acct_type = xaccAccountGetTypeStr(GPOINTER_TO_INT(pw->acct_types->data));
|
||||
gnc_warning_dialog(pw->dialog,
|
||||
_("You have no valid \"Post To\" accounts. "
|
||||
"Please create an account of type \"%s\" "
|
||||
"before you continue to process this payment. "
|
||||
"Perhaps you want to create an Invoice or "
|
||||
"Bill first?"),
|
||||
acct_type);
|
||||
}
|
||||
}
|
||||
|
||||
return pw;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_ui_payment_window_destroy (PaymentWindow *pw)
|
||||
{
|
||||
if (!pw) return;
|
||||
gnc_close_gui_component (pw->component_id);
|
||||
if (!pw) return;
|
||||
gnc_close_gui_component (pw->component_id);
|
||||
}
|
||||
|
||||
PaymentWindow *
|
||||
gnc_ui_payment_new_with_invoice (GncOwner *owner, QofBook *book,
|
||||
GncInvoice *invoice)
|
||||
GncInvoice *invoice)
|
||||
{
|
||||
GncOwner owner_def;
|
||||
GncOwner owner_def;
|
||||
|
||||
if (!book) return NULL;
|
||||
if (owner) {
|
||||
/* Figure out the company */
|
||||
owner = gncOwnerGetEndOwner (owner);
|
||||
} else {
|
||||
gncOwnerInitCustomer (&owner_def, NULL);
|
||||
owner = &owner_def;
|
||||
}
|
||||
if (!book) return NULL;
|
||||
if (owner)
|
||||
{
|
||||
/* Figure out the company */
|
||||
owner = gncOwnerGetEndOwner (owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
gncOwnerInitCustomer (&owner_def, NULL);
|
||||
owner = &owner_def;
|
||||
}
|
||||
|
||||
return new_payment_window (owner, book, invoice);
|
||||
return new_payment_window (owner, book, invoice);
|
||||
}
|
||||
|
||||
PaymentWindow *
|
||||
gnc_ui_payment_new (GncOwner *owner, QofBook *book)
|
||||
{
|
||||
return gnc_ui_payment_new_with_invoice (owner, book, NULL);
|
||||
return gnc_ui_payment_new_with_invoice (owner, book, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ typedef struct _payment_window PaymentWindow;
|
||||
/* Create a payment window */
|
||||
PaymentWindow * gnc_ui_payment_new (GncOwner *owner, QofBook *book);
|
||||
PaymentWindow * gnc_ui_payment_new_with_invoice (GncOwner *owner,
|
||||
QofBook *book,
|
||||
GncInvoice *invoice);
|
||||
QofBook *book,
|
||||
GncInvoice *invoice);
|
||||
|
||||
/* Destroy a payment window */
|
||||
void gnc_ui_payment_window_destroy (PaymentWindow *pw);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* gnc-plugin-business.h --
|
||||
/*
|
||||
* gnc-plugin-business.h --
|
||||
*
|
||||
* Copyright (C) 2003 Jan Arne Petersen
|
||||
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
|
||||
@@ -42,12 +42,14 @@ G_BEGIN_DECLS
|
||||
#define GNC_PLUGIN_BUSINESS_NAME "gnc-plugin-business"
|
||||
|
||||
/* typedefs & structures */
|
||||
typedef struct {
|
||||
GncPlugin gnc_plugin;
|
||||
typedef struct
|
||||
{
|
||||
GncPlugin gnc_plugin;
|
||||
} GncPluginBusiness;
|
||||
|
||||
typedef struct {
|
||||
GncPluginClass gnc_plugin;
|
||||
typedef struct
|
||||
{
|
||||
GncPluginClass gnc_plugin;
|
||||
} GncPluginBusinessClass;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* gnc-plugin-page-invoice.h --
|
||||
/*
|
||||
* gnc-plugin-page-invoice.h --
|
||||
*
|
||||
* Copyright (C) 2005,2006 David Hampton <hampton@employees.org>
|
||||
*
|
||||
@@ -25,7 +25,7 @@
|
||||
@{ */
|
||||
/** @addtogroup InvoicePlugin Business Invoice Page
|
||||
@{ */
|
||||
/** @file gnc-plugin-page-invoice.h
|
||||
/** @file gnc-plugin-page-invoice.h
|
||||
@brief utility functions for the GnuCash UI
|
||||
@author Copyright (C) 2005,2006 David Hampton <hampton@employees.org>
|
||||
*/
|
||||
@@ -52,12 +52,14 @@ G_BEGIN_DECLS
|
||||
#define GNC_PLUGIN_PAGE_INVOICE_NAME "GncPluginPageInvoice"
|
||||
|
||||
/* typedefs & structures */
|
||||
typedef struct {
|
||||
GncPluginPage gnc_plugin_page;
|
||||
typedef struct
|
||||
{
|
||||
GncPluginPage gnc_plugin_page;
|
||||
} GncPluginPageInvoice;
|
||||
|
||||
typedef struct {
|
||||
GncPluginPageClass gnc_plugin_page;
|
||||
typedef struct
|
||||
{
|
||||
GncPluginPageClass gnc_plugin_page;
|
||||
} GncPluginPageInvoiceClass;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
@@ -49,10 +49,11 @@ static void gnc_search_owner_finalize (GObject *obj);
|
||||
|
||||
#define _PRIVATE(x) (((GNCSearchOwner *)(x))->priv)
|
||||
|
||||
typedef struct _GNCSearchOwnerPrivate {
|
||||
GncOwner owner;
|
||||
GtkWidget * owner_box;
|
||||
GtkWidget * owner_choice;
|
||||
typedef struct _GNCSearchOwnerPrivate
|
||||
{
|
||||
GncOwner owner;
|
||||
GtkWidget * owner_box;
|
||||
GtkWidget * owner_choice;
|
||||
} GNCSearchOwnerPrivate;
|
||||
|
||||
#define GNC_SEARCH_OWNER_GET_PRIVATE(o) \
|
||||
@@ -60,8 +61,9 @@ typedef struct _GNCSearchOwnerPrivate {
|
||||
|
||||
static GNCSearchCoreTypeClass *parent_class;
|
||||
|
||||
enum {
|
||||
LAST_SIGNAL
|
||||
enum
|
||||
{
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
#if LAST_SIGNAL > 0
|
||||
@@ -71,47 +73,49 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
||||
GType
|
||||
gnc_search_owner_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (!type) {
|
||||
GTypeInfo type_info = {
|
||||
sizeof(GNCSearchOwnerClass), /* class_size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc)gnc_search_owner_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof(GNCSearchOwner), /* */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc)gnc_search_owner_init,
|
||||
};
|
||||
|
||||
type = g_type_register_static (GNC_TYPE_SEARCH_CORE_TYPE,
|
||||
"GNCSearchOwner",
|
||||
&type_info, 0);
|
||||
}
|
||||
|
||||
return type;
|
||||
static GType type = 0;
|
||||
|
||||
if (!type)
|
||||
{
|
||||
GTypeInfo type_info =
|
||||
{
|
||||
sizeof(GNCSearchOwnerClass), /* class_size */
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc)gnc_search_owner_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof(GNCSearchOwner), /* */
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc)gnc_search_owner_init,
|
||||
};
|
||||
|
||||
type = g_type_register_static (GNC_TYPE_SEARCH_CORE_TYPE,
|
||||
"GNCSearchOwner",
|
||||
&type_info, 0);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_search_owner_class_init (GNCSearchOwnerClass *class)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
|
||||
GObjectClass *object_class;
|
||||
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (class);
|
||||
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
|
||||
object_class = G_OBJECT_CLASS (class);
|
||||
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
|
||||
|
||||
object_class->finalize = gnc_search_owner_finalize;
|
||||
object_class->finalize = gnc_search_owner_finalize;
|
||||
|
||||
/* override methods */
|
||||
gnc_search_core_type->validate = gncs_validate;
|
||||
gnc_search_core_type->get_widget = gncs_get_widget;
|
||||
gnc_search_core_type->get_predicate = gncs_get_predicate;
|
||||
gnc_search_core_type->clone = gncs_clone;
|
||||
/* override methods */
|
||||
gnc_search_core_type->validate = gncs_validate;
|
||||
gnc_search_core_type->get_widget = gncs_get_widget;
|
||||
gnc_search_core_type->get_predicate = gncs_get_predicate;
|
||||
gnc_search_core_type->clone = gncs_clone;
|
||||
|
||||
g_type_class_add_private(class, sizeof(GNCSearchOwnerPrivate));
|
||||
g_type_class_add_private(class, sizeof(GNCSearchOwnerPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -122,126 +126,129 @@ gnc_search_owner_init (GNCSearchOwner *o)
|
||||
static void
|
||||
gnc_search_owner_finalize (GObject *obj)
|
||||
{
|
||||
GNCSearchOwner *o;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GNCSearchOwner *o;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
|
||||
g_assert (IS_GNCSEARCH_OWNER (obj));
|
||||
g_assert (IS_GNCSEARCH_OWNER (obj));
|
||||
|
||||
o = GNCSEARCH_OWNER(obj);
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(o);
|
||||
o = GNCSEARCH_OWNER(obj);
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(o);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize(obj);
|
||||
G_OBJECT_CLASS (parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* gnc_search_owner_new:
|
||||
*
|
||||
* Create a new GNCSearchOwner object.
|
||||
*
|
||||
*
|
||||
* Return value: A new #GNCSearchOwner object.
|
||||
**/
|
||||
GNCSearchOwner *
|
||||
gnc_search_owner_new (void)
|
||||
{
|
||||
GNCSearchOwner *o = g_object_new(gnc_search_owner_get_type (), NULL);
|
||||
return o;
|
||||
GNCSearchOwner *o = g_object_new(gnc_search_owner_get_type (), NULL);
|
||||
return o;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gncs_validate (GNCSearchCoreType *fe)
|
||||
{
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
gboolean valid = TRUE;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
gboolean valid = TRUE;
|
||||
|
||||
g_return_val_if_fail (fi, FALSE);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), FALSE);
|
||||
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
if (priv->owner.owner.undefined == NULL) {
|
||||
valid = FALSE;
|
||||
gnc_error_dialog (NULL, "%s", _("You have not selected an owner"));
|
||||
}
|
||||
g_return_val_if_fail (fi, FALSE);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), FALSE);
|
||||
|
||||
/* XXX */
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
if (priv->owner.owner.undefined == NULL)
|
||||
{
|
||||
valid = FALSE;
|
||||
gnc_error_dialog (NULL, "%s", _("You have not selected an owner"));
|
||||
}
|
||||
|
||||
return valid;
|
||||
/* XXX */
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
static int
|
||||
owner_changed_cb (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
GNCSearchOwner *fe = data;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GNCSearchOwner *fe = data;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
gnc_owner_get_owner (priv->owner_choice, &(priv->owner));
|
||||
return FALSE;
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
gnc_owner_get_owner (priv->owner_choice, &(priv->owner));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
set_owner_widget (GNCSearchOwner *fe)
|
||||
{
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
|
||||
/* Remove the old choice widget */
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
if (priv->owner_choice)
|
||||
gtk_container_remove (GTK_CONTAINER (priv->owner_box), priv->owner_choice);
|
||||
/* Remove the old choice widget */
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
if (priv->owner_choice)
|
||||
gtk_container_remove (GTK_CONTAINER (priv->owner_box), priv->owner_choice);
|
||||
|
||||
/* Create a new choice widget */
|
||||
priv->owner_choice =
|
||||
gnc_owner_select_create (NULL, priv->owner_box,
|
||||
gnc_get_current_book(), &(priv->owner));
|
||||
/* Create a new choice widget */
|
||||
priv->owner_choice =
|
||||
gnc_owner_select_create (NULL, priv->owner_box,
|
||||
gnc_get_current_book(), &(priv->owner));
|
||||
|
||||
/* Setup the "changed" callback */
|
||||
g_signal_connect (G_OBJECT (priv->owner_choice), "changed",
|
||||
G_CALLBACK (owner_changed_cb), fe);
|
||||
/* Setup the "changed" callback */
|
||||
g_signal_connect (G_OBJECT (priv->owner_choice), "changed",
|
||||
G_CALLBACK (owner_changed_cb), fe);
|
||||
|
||||
gtk_widget_show_all (priv->owner_choice);
|
||||
gtk_widget_show_all (priv->owner_choice);
|
||||
}
|
||||
|
||||
static void
|
||||
type_combo_changed (GtkWidget *widget, GNCSearchOwner *fe)
|
||||
{
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GncOwnerType type;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GncOwnerType type;
|
||||
|
||||
g_return_if_fail(GTK_IS_COMBO_BOX(widget));
|
||||
g_return_if_fail(GTK_IS_COMBO_BOX(widget));
|
||||
|
||||
type = gnc_combo_box_search_get_active(GTK_COMBO_BOX(widget));
|
||||
type = gnc_combo_box_search_get_active(GTK_COMBO_BOX(widget));
|
||||
|
||||
/* If the type changed or if we don't have a type create the owner_choice */
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
if (type != gncOwnerGetType (&(priv->owner))) {
|
||||
priv->owner.type = type;
|
||||
priv->owner.owner.undefined = NULL;
|
||||
set_owner_widget (fe);
|
||||
} else if (priv->owner_choice == NULL)
|
||||
set_owner_widget (fe);
|
||||
/* If the type changed or if we don't have a type create the owner_choice */
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fe);
|
||||
if (type != gncOwnerGetType (&(priv->owner)))
|
||||
{
|
||||
priv->owner.type = type;
|
||||
priv->owner.owner.undefined = NULL;
|
||||
set_owner_widget (fe);
|
||||
}
|
||||
else if (priv->owner_choice == NULL)
|
||||
set_owner_widget (fe);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
make_type_menu (GNCSearchCoreType *fe)
|
||||
{
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GtkComboBox *combo;
|
||||
GncOwnerType type;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
GtkComboBox *combo;
|
||||
GncOwnerType type;
|
||||
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
type = gncOwnerGetType (&(priv->owner));
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
type = gncOwnerGetType (&(priv->owner));
|
||||
|
||||
combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
|
||||
gnc_combo_box_search_add(combo, _("Customer"), GNC_OWNER_CUSTOMER);
|
||||
gnc_combo_box_search_add(combo, _("Vendor"), GNC_OWNER_VENDOR);
|
||||
gnc_combo_box_search_add(combo, _("Employee"), GNC_OWNER_EMPLOYEE);
|
||||
gnc_combo_box_search_add(combo, _("Job"), GNC_OWNER_JOB);
|
||||
combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
|
||||
gnc_combo_box_search_add(combo, _("Customer"), GNC_OWNER_CUSTOMER);
|
||||
gnc_combo_box_search_add(combo, _("Vendor"), GNC_OWNER_VENDOR);
|
||||
gnc_combo_box_search_add(combo, _("Employee"), GNC_OWNER_EMPLOYEE);
|
||||
gnc_combo_box_search_add(combo, _("Job"), GNC_OWNER_JOB);
|
||||
|
||||
g_signal_connect (combo, "changed", G_CALLBACK (type_combo_changed), fe);
|
||||
gnc_combo_box_search_set_active(combo, type);
|
||||
g_signal_connect (combo, "changed", G_CALLBACK (type_combo_changed), fe);
|
||||
gnc_combo_box_search_set_active(combo, type);
|
||||
|
||||
return GTK_WIDGET(combo);
|
||||
return GTK_WIDGET(combo);
|
||||
|
||||
|
||||
}
|
||||
@@ -249,82 +256,82 @@ make_type_menu (GNCSearchCoreType *fe)
|
||||
static GtkWidget *
|
||||
make_how_menu (GNCSearchCoreType *fe)
|
||||
{
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GtkComboBox *combo;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GtkComboBox *combo;
|
||||
|
||||
combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
|
||||
gnc_combo_box_search_add(combo, _("is"), GUID_MATCH_ANY);
|
||||
gnc_combo_box_search_add(combo, _("is not"), GUID_MATCH_NONE);
|
||||
gnc_combo_box_search_changed(combo, &fi->how);
|
||||
gnc_combo_box_search_set_active(combo, fi->how ? fi->how : GUID_MATCH_ANY);
|
||||
combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
|
||||
gnc_combo_box_search_add(combo, _("is"), GUID_MATCH_ANY);
|
||||
gnc_combo_box_search_add(combo, _("is not"), GUID_MATCH_NONE);
|
||||
gnc_combo_box_search_changed(combo, &fi->how);
|
||||
gnc_combo_box_search_set_active(combo, fi->how ? fi->how : GUID_MATCH_ANY);
|
||||
|
||||
return GTK_WIDGET(combo);
|
||||
return GTK_WIDGET(combo);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
gncs_get_widget (GNCSearchCoreType *fe)
|
||||
{
|
||||
GtkWidget *how_menu, *type_menu, *box;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (fi, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), NULL);
|
||||
GtkWidget *how_menu, *type_menu, *box;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
box = gtk_hbox_new (FALSE, 3);
|
||||
g_return_val_if_fail (fi, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), NULL);
|
||||
|
||||
/* Build and connect the "how" option menu. */
|
||||
how_menu = make_how_menu (fe);
|
||||
gtk_box_pack_start (GTK_BOX (box), how_menu, FALSE, FALSE, 3);
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
box = gtk_hbox_new (FALSE, 3);
|
||||
|
||||
/* Create the owner box */
|
||||
priv->owner_box = gtk_hbox_new (FALSE, 0);
|
||||
/* Build and connect the "how" option menu. */
|
||||
how_menu = make_how_menu (fe);
|
||||
gtk_box_pack_start (GTK_BOX (box), how_menu, FALSE, FALSE, 3);
|
||||
|
||||
/* Build and connect the "type" option menu.
|
||||
* Note that this will build the owner_choice and
|
||||
* put it in the owner_box we just created.
|
||||
*/
|
||||
type_menu = make_type_menu (fe);
|
||||
gtk_box_pack_start (GTK_BOX (box), type_menu, FALSE, FALSE, 3);
|
||||
/* Create the owner box */
|
||||
priv->owner_box = gtk_hbox_new (FALSE, 0);
|
||||
|
||||
/* connect the owner box */
|
||||
gtk_box_pack_start (GTK_BOX (box), priv->owner_box, FALSE, FALSE, 3);
|
||||
/* Build and connect the "type" option menu.
|
||||
* Note that this will build the owner_choice and
|
||||
* put it in the owner_box we just created.
|
||||
*/
|
||||
type_menu = make_type_menu (fe);
|
||||
gtk_box_pack_start (GTK_BOX (box), type_menu, FALSE, FALSE, 3);
|
||||
|
||||
/* And return the box */
|
||||
return box;
|
||||
/* connect the owner box */
|
||||
gtk_box_pack_start (GTK_BOX (box), priv->owner_box, FALSE, FALSE, 3);
|
||||
|
||||
/* And return the box */
|
||||
return box;
|
||||
}
|
||||
|
||||
static QueryPredData_t gncs_get_predicate (GNCSearchCoreType *fe)
|
||||
{
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
const GUID *guid;
|
||||
GList *l = NULL;
|
||||
GNCSearchOwner *fi = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *priv;
|
||||
const GUID *guid;
|
||||
GList *l = NULL;
|
||||
|
||||
g_return_val_if_fail (fi, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), NULL);
|
||||
g_return_val_if_fail (fi, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fi), NULL);
|
||||
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
guid = gncOwnerGetGUID (&(priv->owner));
|
||||
l = g_list_prepend (l, (gpointer)guid);
|
||||
priv = GNC_SEARCH_OWNER_GET_PRIVATE(fi);
|
||||
guid = gncOwnerGetGUID (&(priv->owner));
|
||||
l = g_list_prepend (l, (gpointer)guid);
|
||||
|
||||
return gncQueryGUIDPredicate (fi->how, l);
|
||||
return gncQueryGUIDPredicate (fi->how, l);
|
||||
}
|
||||
|
||||
static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
|
||||
{
|
||||
GNCSearchOwner *se, *fse = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *se_priv, *fse_priv;
|
||||
GNCSearchOwner *se, *fse = (GNCSearchOwner *)fe;
|
||||
GNCSearchOwnerPrivate *se_priv, *fse_priv;
|
||||
|
||||
g_return_val_if_fail (fse, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fse), NULL);
|
||||
g_return_val_if_fail (fse, NULL);
|
||||
g_return_val_if_fail (IS_GNCSEARCH_OWNER (fse), NULL);
|
||||
|
||||
se = gnc_search_owner_new ();
|
||||
se->how = fse->how;
|
||||
se_priv = GNC_SEARCH_OWNER_GET_PRIVATE(se);
|
||||
fse_priv = GNC_SEARCH_OWNER_GET_PRIVATE(fse);
|
||||
gncOwnerCopy (&(fse_priv->owner), &(se_priv->owner));
|
||||
se = gnc_search_owner_new ();
|
||||
se->how = fse->how;
|
||||
se_priv = GNC_SEARCH_OWNER_GET_PRIVATE(se);
|
||||
fse_priv = GNC_SEARCH_OWNER_GET_PRIVATE(fse);
|
||||
gncOwnerCopy (&(fse_priv->owner), &(se_priv->owner));
|
||||
|
||||
return (GNCSearchCoreType *)se;
|
||||
return (GNCSearchCoreType *)se;
|
||||
}
|
||||
|
||||
@@ -32,18 +32,20 @@
|
||||
typedef struct _GNCSearchOwner GNCSearchOwner;
|
||||
typedef struct _GNCSearchOwnerClass GNCSearchOwnerClass;
|
||||
|
||||
struct _GNCSearchOwner {
|
||||
GNCSearchCoreType parent;
|
||||
struct _GNCSearchOwner
|
||||
{
|
||||
GNCSearchCoreType parent;
|
||||
|
||||
guid_match_t how;
|
||||
guid_match_t how;
|
||||
};
|
||||
|
||||
struct _GNCSearchOwnerClass {
|
||||
GNCSearchCoreTypeClass parent_class;
|
||||
struct _GNCSearchOwnerClass
|
||||
{
|
||||
GNCSearchCoreTypeClass parent_class;
|
||||
|
||||
/* virtual methods */
|
||||
/* virtual methods */
|
||||
|
||||
/* signals */
|
||||
/* signals */
|
||||
};
|
||||
|
||||
GType gnc_search_owner_get_type (void);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,27 +30,28 @@
|
||||
#include "gnc-book.h"
|
||||
#include "table-allgui.h"
|
||||
|
||||
typedef enum {
|
||||
GNCENTRY_ORDER_ENTRY,
|
||||
GNCENTRY_ORDER_VIEWER,
|
||||
GNCENTRY_INVOICE_ENTRY,
|
||||
GNCENTRY_INVOICE_VIEWER,
|
||||
GNCENTRY_BILL_ENTRY,
|
||||
GNCENTRY_BILL_VIEWER,
|
||||
GNCENTRY_EXPVOUCHER_ENTRY,
|
||||
GNCENTRY_EXPVOUCHER_VIEWER,
|
||||
GNCENTRY_NUM_REGISTER_TYPES
|
||||
typedef enum
|
||||
{
|
||||
GNCENTRY_ORDER_ENTRY,
|
||||
GNCENTRY_ORDER_VIEWER,
|
||||
GNCENTRY_INVOICE_ENTRY,
|
||||
GNCENTRY_INVOICE_VIEWER,
|
||||
GNCENTRY_BILL_ENTRY,
|
||||
GNCENTRY_BILL_VIEWER,
|
||||
GNCENTRY_EXPVOUCHER_ENTRY,
|
||||
GNCENTRY_EXPVOUCHER_VIEWER,
|
||||
GNCENTRY_NUM_REGISTER_TYPES
|
||||
} GncEntryLedgerType;
|
||||
|
||||
typedef struct entry_ledger_colors
|
||||
{
|
||||
guint32 header_bg_color;
|
||||
guint32 header_bg_color;
|
||||
|
||||
guint32 primary_bg_color;
|
||||
guint32 secondary_bg_color;
|
||||
guint32 primary_bg_color;
|
||||
guint32 secondary_bg_color;
|
||||
|
||||
guint32 primary_active_bg_color;
|
||||
guint32 secondary_active_bg_color;
|
||||
guint32 primary_active_bg_color;
|
||||
guint32 secondary_active_bg_color;
|
||||
} GncEntryLedgerColors;
|
||||
|
||||
#define ENTRY_IACCT_CELL "inv-account"
|
||||
@@ -83,11 +84,11 @@ GncEntryLedger * gnc_entry_ledger_new (QofBook *book, GncEntryLedgerType type);
|
||||
|
||||
/* Set the default order for this ledger */
|
||||
void gnc_entry_ledger_set_default_order (GncEntryLedger *ledger,
|
||||
GncOrder *order);
|
||||
GncOrder *order);
|
||||
|
||||
/* Set the default invoice for this ledger */
|
||||
void gnc_entry_ledger_set_default_invoice (GncEntryLedger *ledger,
|
||||
GncInvoice *invoice);
|
||||
GncInvoice *invoice);
|
||||
|
||||
/* Destroy the GncEntry Ledger */
|
||||
void gnc_entry_ledger_destroy (GncEntryLedger *ledger);
|
||||
@@ -122,8 +123,8 @@ void gnc_entry_ledger_reset_query (GncEntryLedger *ledger);
|
||||
GncEntry * gnc_entry_ledger_get_blank_entry (GncEntryLedger *ledger);
|
||||
|
||||
gboolean gnc_entry_ledger_get_entry_virt_loc (GncEntryLedger *ledger,
|
||||
GncEntry *entry,
|
||||
VirtualCellLocation *vcell_loc);
|
||||
GncEntry *entry,
|
||||
VirtualCellLocation *vcell_loc);
|
||||
|
||||
void gnc_entry_ledger_delete_current_entry (GncEntryLedger *ledger);
|
||||
void gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,162 +40,168 @@
|
||||
static GList *
|
||||
gnc_entry_ledger_get_entries (GncEntryLedger *ledger)
|
||||
{
|
||||
if (ledger->query)
|
||||
return gncQueryRun (ledger->query);
|
||||
if (ledger->query)
|
||||
return gncQueryRun (ledger->query);
|
||||
|
||||
// g_warning ("No query to run?");
|
||||
return NULL;
|
||||
// g_warning ("No query to run?");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_refresh_internal (GncEntryLedger *ledger, GList *entries)
|
||||
{
|
||||
if (!ledger || ledger->loading)
|
||||
return;
|
||||
if (!ledger || ledger->loading)
|
||||
return;
|
||||
|
||||
/* If not full refresh ok, just load the xfer cells */
|
||||
if (!ledger->full_refresh) {
|
||||
gnc_entry_ledger_load_xfer_cells (ledger);
|
||||
return;
|
||||
}
|
||||
/* If not full refresh ok, just load the xfer cells */
|
||||
if (!ledger->full_refresh)
|
||||
{
|
||||
gnc_entry_ledger_load_xfer_cells (ledger);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Viewers must always have at least one entry! */
|
||||
if ((ledger->type == GNCENTRY_ORDER_VIEWER ||
|
||||
ledger->type == GNCENTRY_INVOICE_VIEWER ||
|
||||
ledger->type == GNCENTRY_BILL_VIEWER ||
|
||||
ledger->type == GNCENTRY_EXPVOUCHER_VIEWER) && !entries)
|
||||
return;
|
||||
/* Viewers must always have at least one entry! */
|
||||
if ((ledger->type == GNCENTRY_ORDER_VIEWER ||
|
||||
ledger->type == GNCENTRY_INVOICE_VIEWER ||
|
||||
ledger->type == GNCENTRY_BILL_VIEWER ||
|
||||
ledger->type == GNCENTRY_EXPVOUCHER_VIEWER) && !entries)
|
||||
return;
|
||||
|
||||
ledger->loading = TRUE;
|
||||
gnc_entry_ledger_load (ledger, entries);
|
||||
ledger->loading = FALSE;
|
||||
ledger->loading = TRUE;
|
||||
gnc_entry_ledger_load (ledger, entries);
|
||||
ledger->loading = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_gconf_changed (GConfEntry *entry, gpointer user_data)
|
||||
{
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntryLedger *ledger = user_data;
|
||||
|
||||
g_return_if_fail (ledger && entry && entry->key);
|
||||
g_return_if_fail (ledger && entry && entry->key);
|
||||
|
||||
if (g_str_has_suffix (entry->key, KEY_ACCOUNT_SEPARATOR)) {
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
} else {
|
||||
g_warning ("gnc_entry_gconf_changed: Unknown gconf key %s", entry->key);
|
||||
}
|
||||
if (g_str_has_suffix (entry->key, KEY_ACCOUNT_SEPARATOR))
|
||||
{
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning ("gnc_entry_gconf_changed: Unknown gconf key %s", entry->key);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_set_watches (GncEntryLedger *ledger, GList *entries)
|
||||
{
|
||||
GList *node;
|
||||
GNCIdType type = NULL;
|
||||
GList *node;
|
||||
GNCIdType type = NULL;
|
||||
|
||||
gnc_gui_component_clear_watches (ledger->component_id);
|
||||
gnc_gui_component_clear_watches (ledger->component_id);
|
||||
|
||||
switch (ledger->type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
type = GNC_ORDER_MODULE_NAME;
|
||||
break;
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
type = GNC_ORDER_MODULE_NAME;
|
||||
break;
|
||||
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
/* Watch the invoice owner to see when items get added via orders */
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncOwnerGetGUID
|
||||
(gncInvoiceGetOwner (ledger->invoice)),
|
||||
QOF_EVENT_MODIFY);
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
type = GNC_INVOICE_MODULE_NAME;
|
||||
break;
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
/* Watch the invoice owner to see when items get added via orders */
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncOwnerGetGUID
|
||||
(gncInvoiceGetOwner (ledger->invoice)),
|
||||
QOF_EVENT_MODIFY);
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
type = GNC_INVOICE_MODULE_NAME;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_warning ("Invalid ledger type");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_warning ("Invalid ledger type");
|
||||
break;
|
||||
}
|
||||
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
type,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
type,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
|
||||
/* To make sure the xfer cell is up to date */
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY
|
||||
| GNC_EVENT_ITEM_CHANGED);
|
||||
/* To make sure the xfer cell is up to date */
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
GNC_ID_ACCOUNT,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY
|
||||
| GNC_EVENT_ITEM_CHANGED);
|
||||
|
||||
/* To make sure the taxtable cell is up to date */
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
GNC_TAXTABLE_MODULE_NAME,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
/* To make sure the taxtable cell is up to date */
|
||||
gnc_gui_component_watch_entity_type (ledger->component_id,
|
||||
GNC_TAXTABLE_MODULE_NAME,
|
||||
QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
|
||||
|
||||
/* For expense vouchers, watch the employee and refresh if it's changed */
|
||||
if (ledger->type == GNCENTRY_EXPVOUCHER_ENTRY) {
|
||||
GncOwner *owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
|
||||
GncEmployee *employee = gncOwnerGetEmployee (owner);
|
||||
/* For expense vouchers, watch the employee and refresh if it's changed */
|
||||
if (ledger->type == GNCENTRY_EXPVOUCHER_ENTRY)
|
||||
{
|
||||
GncOwner *owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
|
||||
GncEmployee *employee = gncOwnerGetEmployee (owner);
|
||||
|
||||
if (employee)
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncEmployeeGetGUID (employee),
|
||||
QOF_EVENT_MODIFY);
|
||||
}
|
||||
if (employee)
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncEmployeeGetGUID (employee),
|
||||
QOF_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
for (node = entries; node; node = node->next)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncEntryGetGUID (entry),
|
||||
QOF_EVENT_MODIFY);
|
||||
}
|
||||
for (node = entries; node; node = node->next)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
gnc_gui_component_watch_entity (ledger->component_id,
|
||||
gncEntryGetGUID (entry),
|
||||
QOF_EVENT_MODIFY);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
refresh_handler (GHashTable *changes, gpointer user_data)
|
||||
{
|
||||
GncEntryLedger *ledger = user_data;
|
||||
GncEntryLedger *ledger = user_data;
|
||||
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_entry_ledger_display_init (GncEntryLedger *ledger)
|
||||
{
|
||||
if (!ledger) return;
|
||||
if (!ledger) return;
|
||||
|
||||
ledger->full_refresh = TRUE;
|
||||
ledger->component_id = gnc_register_gui_component (ENTRYLEDGER_CLASS,
|
||||
refresh_handler,
|
||||
NULL, ledger);
|
||||
gnc_gconf_general_register_cb(KEY_ACCOUNT_SEPARATOR,
|
||||
gnc_entry_ledger_gconf_changed, ledger);
|
||||
ledger->full_refresh = TRUE;
|
||||
ledger->component_id = gnc_register_gui_component (ENTRYLEDGER_CLASS,
|
||||
refresh_handler,
|
||||
NULL, ledger);
|
||||
gnc_gconf_general_register_cb(KEY_ACCOUNT_SEPARATOR,
|
||||
gnc_entry_ledger_gconf_changed, ledger);
|
||||
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
gnc_entry_ledger_display_refresh (ledger);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_entry_ledger_display_fini (GncEntryLedger *ledger)
|
||||
{
|
||||
if (!ledger) return;
|
||||
if (!ledger) return;
|
||||
|
||||
gnc_unregister_gui_component (ledger->component_id);
|
||||
gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR,
|
||||
gnc_entry_ledger_gconf_changed, ledger);
|
||||
gnc_unregister_gui_component (ledger->component_id);
|
||||
gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR,
|
||||
gnc_entry_ledger_gconf_changed, ledger);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_entry_ledger_display_refresh (GncEntryLedger *ledger)
|
||||
{
|
||||
GList *entries;
|
||||
GList *entries;
|
||||
|
||||
if (!ledger || ledger->loading) return;
|
||||
if (!ledger || ledger->loading) return;
|
||||
|
||||
entries = gnc_entry_ledger_get_entries (ledger);
|
||||
entries = gnc_entry_ledger_get_entries (ledger);
|
||||
|
||||
gnc_entry_ledger_set_watches (ledger, entries);
|
||||
gnc_entry_ledger_set_watches (ledger, entries);
|
||||
|
||||
gnc_entry_ledger_refresh_internal (ledger, entries);
|
||||
gnc_entry_ledger_refresh_internal (ledger, entries);
|
||||
}
|
||||
|
||||
@@ -38,203 +38,243 @@ gnc_register_add_cell (TableLayout *layout,
|
||||
gboolean expandable,
|
||||
gboolean span)
|
||||
{
|
||||
BasicCell *cell;
|
||||
BasicCell *cell;
|
||||
|
||||
g_return_if_fail (layout != NULL);
|
||||
g_return_if_fail (cell_type_name != NULL);
|
||||
g_return_if_fail (layout != NULL);
|
||||
g_return_if_fail (cell_type_name != NULL);
|
||||
|
||||
cell = gnc_register_make_cell (cell_type_name);
|
||||
cell = gnc_register_make_cell (cell_type_name);
|
||||
|
||||
gnc_basic_cell_set_name (cell, cell_name);
|
||||
gnc_basic_cell_set_sample_text (cell, sample_text);
|
||||
gnc_basic_cell_set_alignment (cell, alignment);
|
||||
gnc_basic_cell_set_expandable (cell, expandable);
|
||||
gnc_basic_cell_set_span (cell, span);
|
||||
gnc_basic_cell_set_name (cell, cell_name);
|
||||
gnc_basic_cell_set_sample_text (cell, sample_text);
|
||||
gnc_basic_cell_set_alignment (cell, alignment);
|
||||
gnc_basic_cell_set_expandable (cell, expandable);
|
||||
gnc_basic_cell_set_span (cell, span);
|
||||
|
||||
gnc_table_layout_add_cell (layout, cell);
|
||||
gnc_table_layout_add_cell (layout, cell);
|
||||
}
|
||||
|
||||
static void gnc_entry_ledger_layout_add_cells (GncEntryLedger *ledger,
|
||||
TableLayout *layout)
|
||||
TableLayout *layout)
|
||||
{
|
||||
struct cell_list {
|
||||
const char *cell_name;
|
||||
const char *cell_type_name;
|
||||
const char *sample_text;
|
||||
CellAlignment alignment;
|
||||
gboolean expandable;
|
||||
gboolean span;
|
||||
} cells[] = {
|
||||
/* Translators: The 'sample:' items are strings which are not
|
||||
displayed, but only used to estimate widths. Please only
|
||||
translate the portion after the ':' and leave the rest
|
||||
("sample:") as is. */
|
||||
{ ENTRY_INV_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:X")+7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
{ ENTRY_DATE_CELL, DATE_CELL_TYPE_NAME, N_("sample:12/12/2000")+7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_DESC_CELL, QUICKFILL_CELL_TYPE_NAME,
|
||||
N_("sample:Description of an Entry")+7, CELL_ALIGN_LEFT, TRUE, FALSE },
|
||||
{ ENTRY_ACTN_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Action")+7, CELL_ALIGN_RIGHT,
|
||||
FALSE, FALSE },
|
||||
{ ENTRY_QTY_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_PRIC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_DISC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
/* xgettext:no-c-format */
|
||||
{ ENTRY_DISTYPE_CELL, RECN_CELL_TYPE_NAME, N_("sample(DT):+%")+11,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
/* xgettext:no-c-format */
|
||||
{ ENTRY_DISHOW_CELL, RECN_CELL_TYPE_NAME, N_("sample(DH):+%")+11,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
{ ENTRY_IACCT_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Expenses:Automobile:Gasoline") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_BACCT_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Expenses:Automobile:Gasoline") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_TAXABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:T?")+7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
{ ENTRY_TAXINCLUDED_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:TI")+7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
{ ENTRY_TAXTABLE_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Tax Table 1")+7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_VALUE_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00")+7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_TAXVAL_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999.00")+7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE },
|
||||
{ ENTRY_BILLABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:BI")+7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE },
|
||||
{ ENTRY_PAYMENT_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Payment")+7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE }
|
||||
};
|
||||
unsigned int i;
|
||||
struct cell_list
|
||||
{
|
||||
const char *cell_name;
|
||||
const char *cell_type_name;
|
||||
const char *sample_text;
|
||||
CellAlignment alignment;
|
||||
gboolean expandable;
|
||||
gboolean span;
|
||||
} cells[] =
|
||||
{
|
||||
/* Translators: The 'sample:' items are strings which are not
|
||||
displayed, but only used to estimate widths. Please only
|
||||
translate the portion after the ':' and leave the rest
|
||||
("sample:") as is. */
|
||||
{
|
||||
ENTRY_INV_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:X") + 7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_DATE_CELL, DATE_CELL_TYPE_NAME, N_("sample:12/12/2000") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_DESC_CELL, QUICKFILL_CELL_TYPE_NAME,
|
||||
N_("sample:Description of an Entry") + 7, CELL_ALIGN_LEFT, TRUE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_ACTN_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Action") + 7, CELL_ALIGN_RIGHT,
|
||||
FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_QTY_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_PRIC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_DISC_CELL, PRICE_CELL_TYPE_NAME, N_("sample:9,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
/* xgettext:no-c-format */
|
||||
{
|
||||
ENTRY_DISTYPE_CELL, RECN_CELL_TYPE_NAME, N_("sample(DT):+%") + 11,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
/* xgettext:no-c-format */
|
||||
{
|
||||
ENTRY_DISHOW_CELL, RECN_CELL_TYPE_NAME, N_("sample(DH):+%") + 11,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_IACCT_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Expenses:Automobile:Gasoline") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_BACCT_CELL, COMBO_CELL_TYPE_NAME,
|
||||
N_("sample:Expenses:Automobile:Gasoline") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_TAXABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:T?") + 7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_TAXINCLUDED_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:TI") + 7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_TAXTABLE_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Tax Table 1") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_VALUE_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999,999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_TAXVAL_CELL, PRICE_CELL_TYPE_NAME, N_("sample:999.00") + 7,
|
||||
CELL_ALIGN_RIGHT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_BILLABLE_CELL, CHECKBOX_CELL_TYPE_NAME, N_("sample:BI") + 7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
},
|
||||
{
|
||||
ENTRY_PAYMENT_CELL, COMBO_CELL_TYPE_NAME, N_("sample:Payment") + 7,
|
||||
CELL_ALIGN_LEFT, FALSE, FALSE
|
||||
}
|
||||
};
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < (sizeof(cells)/sizeof(*cells)); i++)
|
||||
gnc_register_add_cell (layout, cells[i].cell_name, cells[i].cell_type_name,
|
||||
cells[i].sample_text, cells[i].alignment,
|
||||
cells[i].expandable, cells[i].span);
|
||||
for (i = 0; i < (sizeof(cells) / sizeof(*cells)); i++)
|
||||
gnc_register_add_cell (layout, cells[i].cell_name, cells[i].cell_type_name,
|
||||
cells[i].sample_text, cells[i].alignment,
|
||||
cells[i].expandable, cells[i].span);
|
||||
}
|
||||
|
||||
static void gnc_entry_ledger_layout_add_cursors (GncEntryLedger *ledger,
|
||||
TableLayout *layout)
|
||||
TableLayout *layout)
|
||||
{
|
||||
CellBlock *cursor;
|
||||
int num_cols;
|
||||
CellBlock *cursor;
|
||||
int num_cols;
|
||||
|
||||
switch (ledger->type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
num_cols = 15;
|
||||
break;
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
num_cols = 12;
|
||||
break;
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
num_cols = 10;
|
||||
break;
|
||||
default:
|
||||
g_assert (FALSE);
|
||||
return;
|
||||
}
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
num_cols = 15;
|
||||
break;
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
num_cols = 12;
|
||||
break;
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
num_cols = 10;
|
||||
break;
|
||||
default:
|
||||
g_assert (FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
cursor = gnc_cellblock_new (1, num_cols, CURSOR_HEADER);
|
||||
gnc_table_layout_add_cursor (layout, cursor);
|
||||
cursor = gnc_cellblock_new (1, num_cols, CURSOR_HEADER);
|
||||
gnc_table_layout_add_cursor (layout, cursor);
|
||||
|
||||
cursor = gnc_cellblock_new (1, num_cols, "cursor");
|
||||
gnc_table_layout_add_cursor (layout, cursor);
|
||||
gnc_table_layout_set_primary_cursor (layout, cursor);
|
||||
cursor = gnc_cellblock_new (1, num_cols, "cursor");
|
||||
gnc_table_layout_add_cursor (layout, cursor);
|
||||
gnc_table_layout_set_primary_cursor (layout, cursor);
|
||||
}
|
||||
|
||||
static void gnc_entry_ledger_set_cells (GncEntryLedger *ledger,
|
||||
TableLayout *layout)
|
||||
TableLayout *layout)
|
||||
{
|
||||
CellBlock *curs;
|
||||
CellBlock *curs;
|
||||
|
||||
switch (ledger->type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_IACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISTYPE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISHOW_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISC_CELL, 0, 9);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 10);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 11);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 12);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 13);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXVAL_CELL, 0, 14);
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_IACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISTYPE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISHOW_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DISC_CELL, 0, 9);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 10);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 11);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 12);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 13);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXVAL_CELL, 0, 14);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 9);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 10);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 11);
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXABLE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXINCLUDED_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_TAXTABLE_CELL, 0, 9);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 10);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 11);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PAYMENT_CELL, 0, 9);
|
||||
curs = gnc_table_layout_get_cursor (layout, "cursor");
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DATE_CELL, 0, 0);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_INV_CELL, 0, 1);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_DESC_CELL, 0, 2);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_ACTN_CELL, 0, 3);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BACCT_CELL, 0, 4);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_QTY_CELL, 0, 5);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PRIC_CELL, 0, 6);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_VALUE_CELL, 0, 7);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_BILLABLE_CELL, 0, 8);
|
||||
gnc_table_layout_set_cell (layout, curs, ENTRY_PAYMENT_CELL, 0, 9);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert (FALSE);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
g_assert (FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TableLayout * gnc_entry_ledger_layout_new (GncEntryLedger *ledger)
|
||||
{
|
||||
TableLayout *layout;
|
||||
TableLayout *layout;
|
||||
|
||||
layout = gnc_table_layout_new ();
|
||||
gnc_entry_ledger_layout_add_cells (ledger, layout);
|
||||
gnc_entry_ledger_layout_add_cursors (ledger, layout);
|
||||
gnc_entry_ledger_set_cells (ledger, layout);
|
||||
layout = gnc_table_layout_new ();
|
||||
gnc_entry_ledger_layout_add_cells (ledger, layout);
|
||||
gnc_entry_ledger_layout_add_cursors (ledger, layout);
|
||||
gnc_entry_ledger_set_cells (ledger, layout);
|
||||
|
||||
return layout;
|
||||
return layout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,81 +45,88 @@
|
||||
/* XXX: This should go elsewhere */
|
||||
const char * gnc_entry_ledger_type_string_getter (char flag)
|
||||
{
|
||||
switch (flag) {
|
||||
case '1': return _("$");
|
||||
case '2': return _("%");
|
||||
default:
|
||||
return "?";
|
||||
};
|
||||
switch (flag)
|
||||
{
|
||||
case '1':
|
||||
return _("$");
|
||||
case '2':
|
||||
return _("%");
|
||||
default:
|
||||
return "?";
|
||||
};
|
||||
}
|
||||
|
||||
const char * gnc_entry_ledger_how_string_getter (char flag)
|
||||
{
|
||||
switch (flag) {
|
||||
case '1': return _("<");
|
||||
case '2': return _("=");
|
||||
case '3': return _(">");
|
||||
default:
|
||||
return "?";
|
||||
};
|
||||
switch (flag)
|
||||
{
|
||||
case '1':
|
||||
return _("<");
|
||||
case '2':
|
||||
return _("=");
|
||||
case '3':
|
||||
return _(">");
|
||||
default:
|
||||
return "?";
|
||||
};
|
||||
}
|
||||
|
||||
static void load_discount_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell *cell;
|
||||
|
||||
if (!ledger) return;
|
||||
if (!ledger) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISTYPE_CELL);
|
||||
cell = (RecnCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISTYPE_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
if (!cell) return;
|
||||
|
||||
gnc_recn_cell_set_valid_flags (cell, "12", '2');
|
||||
gnc_recn_cell_set_flag_order (cell, "21");
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
|
||||
gnc_recn_cell_set_valid_flags (cell, "12", '2');
|
||||
gnc_recn_cell_set_flag_order (cell, "21");
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_type_string_getter);
|
||||
}
|
||||
|
||||
static void load_discount_how_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
RecnCell *cell;
|
||||
RecnCell *cell;
|
||||
|
||||
if (!ledger) return;
|
||||
if (!ledger) return;
|
||||
|
||||
cell = (RecnCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISHOW_CELL);
|
||||
cell = (RecnCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DISHOW_CELL);
|
||||
|
||||
if (!cell) return;
|
||||
if (!cell) return;
|
||||
|
||||
gnc_recn_cell_set_valid_flags (cell, "123", '1');
|
||||
gnc_recn_cell_set_flag_order (cell, "123");
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_how_string_getter);
|
||||
gnc_recn_cell_set_valid_flags (cell, "123", '1');
|
||||
gnc_recn_cell_set_flag_order (cell, "123");
|
||||
gnc_recn_cell_set_string_getter (cell, gnc_entry_ledger_how_string_getter);
|
||||
}
|
||||
|
||||
static void load_payment_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
ComboCell *cell;
|
||||
GncOwner *owner;
|
||||
GncEmployee *employee;
|
||||
ComboCell *cell;
|
||||
GncOwner *owner;
|
||||
GncEmployee *employee;
|
||||
|
||||
cell = (ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_PAYMENT_CELL);
|
||||
if (!cell) return;
|
||||
cell = (ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
|
||||
ENTRY_PAYMENT_CELL);
|
||||
if (!cell) return;
|
||||
|
||||
if (!ledger->invoice) return;
|
||||
if (!ledger->invoice) return;
|
||||
|
||||
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
|
||||
if (gncOwnerGetType (owner) != GNC_OWNER_EMPLOYEE)
|
||||
return;
|
||||
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
|
||||
if (gncOwnerGetType (owner) != GNC_OWNER_EMPLOYEE)
|
||||
return;
|
||||
|
||||
employee = gncOwnerGetEmployee (owner);
|
||||
g_return_if_fail (employee);
|
||||
employee = gncOwnerGetEmployee (owner);
|
||||
g_return_if_fail (employee);
|
||||
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
gnc_combo_cell_add_menu_item (cell, _("Cash"));
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
gnc_combo_cell_add_menu_item (cell, _("Cash"));
|
||||
|
||||
if (gncEmployeeGetCCard (employee))
|
||||
gnc_combo_cell_add_menu_item (cell, _("Charge"));
|
||||
if (gncEmployeeGetCCard (employee))
|
||||
gnc_combo_cell_add_menu_item (cell, _("Charge"));
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
@@ -128,47 +135,47 @@ static void load_payment_type_cells (GncEntryLedger *ledger)
|
||||
static gboolean
|
||||
skip_expense_acct_cb (Account *account, gpointer user_data)
|
||||
{
|
||||
GNCAccountType type;
|
||||
GNCAccountType type;
|
||||
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If this is an ORDER or INVOICE, then leave out the expenses. */
|
||||
if (type == ACCT_TYPE_EXPENSE) return TRUE;
|
||||
/* If this is an ORDER or INVOICE, then leave out the expenses. */
|
||||
if (type == ACCT_TYPE_EXPENSE) return TRUE;
|
||||
|
||||
/* Don't add placeholder accounts */
|
||||
if (xaccAccountGetPlaceholder (account)) return TRUE;
|
||||
/* Don't add placeholder accounts */
|
||||
if (xaccAccountGetPlaceholder (account)) return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
skip_income_acct_cb (Account *account, gpointer user_data)
|
||||
{
|
||||
GNCAccountType type;
|
||||
GNCAccountType type;
|
||||
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
/* Don't add A/R, A/P, Bank, Cash, or Equity accounts */
|
||||
type = xaccAccountGetType (account);
|
||||
if (type == ACCT_TYPE_PAYABLE || type == ACCT_TYPE_RECEIVABLE ||
|
||||
type == ACCT_TYPE_CASH || type == ACCT_TYPE_BANK ||
|
||||
type == ACCT_TYPE_EQUITY || type == ACCT_TYPE_TRADING)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If this is a BILL, then leave out the incomes */
|
||||
if (type == ACCT_TYPE_INCOME) return TRUE;
|
||||
/* If this is a BILL, then leave out the incomes */
|
||||
if (type == ACCT_TYPE_INCOME) return TRUE;
|
||||
|
||||
/* Don't add placeholder accounts */
|
||||
if (xaccAccountGetPlaceholder (account)) return TRUE;
|
||||
/* Don't add placeholder accounts */
|
||||
if (xaccAccountGetPlaceholder (account)) return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* ===================================================================== */
|
||||
@@ -177,95 +184,96 @@ skip_income_acct_cb (Account *account, gpointer user_data)
|
||||
#define EKEY "Expense Business entry quickfill"
|
||||
#define IKEY "Income Business entry quickfill"
|
||||
|
||||
static void
|
||||
static void
|
||||
load_xfer_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
Account *root;
|
||||
ComboCell *cell;
|
||||
QuickFill *qf=NULL;
|
||||
GtkListStore *store = NULL;
|
||||
Account *root;
|
||||
ComboCell *cell;
|
||||
QuickFill *qf = NULL;
|
||||
GtkListStore *store = NULL;
|
||||
|
||||
root = gnc_book_get_root_account (ledger->book);
|
||||
if (root == NULL) return;
|
||||
root = gnc_book_get_root_account (ledger->book);
|
||||
if (root == NULL) return;
|
||||
|
||||
/* Use a common, shared quickfill. For the ORDER or INVOICE,
|
||||
* ledgers, we don't want expense-type accounts in the menu.
|
||||
* For BILL, etc. then leave out the income types.
|
||||
*/
|
||||
switch (ledger->type)
|
||||
{
|
||||
/* Use a common, shared quickfill. For the ORDER or INVOICE,
|
||||
* ledgers, we don't want expense-type accounts in the menu.
|
||||
* For BILL, etc. then leave out the income types.
|
||||
*/
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_ORDER_VIEWER:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_INVOICE_VIEWER:
|
||||
qf = gnc_get_shared_account_name_quickfill (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
break;
|
||||
qf = gnc_get_shared_account_name_quickfill (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, IKEY,
|
||||
skip_expense_acct_cb, NULL);
|
||||
break;
|
||||
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_BILL_VIEWER:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_VIEWER:
|
||||
case GNCENTRY_NUM_REGISTER_TYPES:
|
||||
qf = gnc_get_shared_account_name_quickfill (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
break;
|
||||
}
|
||||
qf = gnc_get_shared_account_name_quickfill (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
store = gnc_get_shared_account_name_list_store (root, EKEY,
|
||||
skip_income_acct_cb, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_IACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_BACCT_CELL);
|
||||
gnc_combo_cell_use_quickfill_cache (cell, qf);
|
||||
gnc_combo_cell_use_list_store_cache (cell, store);
|
||||
}
|
||||
|
||||
/* ===================================================================== */
|
||||
|
||||
static void load_taxtable_type_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
GList *list;
|
||||
ComboCell *cell;
|
||||
GList *list;
|
||||
ComboCell *cell;
|
||||
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXTABLE_CELL);
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
|
||||
list = gncTaxTableGetTables (ledger->book);
|
||||
for ( ; list ; list = list->next ) {
|
||||
GncTaxTable *table = list->data;
|
||||
const char *name = gncTaxTableGetName (table);
|
||||
if (name != NULL)
|
||||
gnc_combo_cell_add_menu_item (cell, (char*)name);
|
||||
}
|
||||
cell = (ComboCell *)
|
||||
gnc_table_layout_get_cell (ledger->table->layout, ENTRY_TAXTABLE_CELL);
|
||||
gnc_combo_cell_clear_menu (cell);
|
||||
|
||||
list = gncTaxTableGetTables (ledger->book);
|
||||
for ( ; list ; list = list->next )
|
||||
{
|
||||
GncTaxTable *table = list->data;
|
||||
const char *name = gncTaxTableGetName (table);
|
||||
if (name != NULL)
|
||||
gnc_combo_cell_add_menu_item (cell, (char*)name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_entry_ledger_show_entry (GncEntryLedger *ledger,
|
||||
VirtualCellLocation start_loc)
|
||||
VirtualCellLocation start_loc)
|
||||
{
|
||||
VirtualCellLocation end_loc;
|
||||
int v_row;
|
||||
VirtualCellLocation end_loc;
|
||||
int v_row;
|
||||
|
||||
end_loc = start_loc;
|
||||
v_row = end_loc.virt_row + 1;
|
||||
end_loc.virt_row = MIN (v_row, ledger->table->num_virt_rows - 1);
|
||||
end_loc = start_loc;
|
||||
v_row = end_loc.virt_row + 1;
|
||||
end_loc.virt_row = MIN (v_row, ledger->table->num_virt_rows - 1);
|
||||
|
||||
gnc_table_show_range (ledger->table, start_loc, end_loc);
|
||||
gnc_table_show_range (ledger->table, start_loc, end_loc);
|
||||
}
|
||||
|
||||
void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
|
||||
{
|
||||
load_xfer_type_cells (ledger);
|
||||
load_taxtable_type_cells (ledger);
|
||||
load_payment_type_cells (ledger);
|
||||
load_xfer_type_cells (ledger);
|
||||
load_taxtable_type_cells (ledger);
|
||||
load_payment_type_cells (ledger);
|
||||
}
|
||||
|
||||
/* XXX (FIXME): This should be in a config file! */
|
||||
@@ -276,265 +284,284 @@ void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
|
||||
*/
|
||||
void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
{
|
||||
GncEntry *blank_entry, *find_entry;
|
||||
CursorBuffer *cursor_buffer;
|
||||
Table *table;
|
||||
GncEntry *blank_entry, *find_entry;
|
||||
CursorBuffer *cursor_buffer;
|
||||
Table *table;
|
||||
|
||||
GList *node;
|
||||
CellBlock *cursor_header, *cursor;
|
||||
VirtualCellLocation vcell_loc;
|
||||
VirtualLocation save_loc;
|
||||
time_t present;
|
||||
gboolean start_primary_color = TRUE;
|
||||
GList *node;
|
||||
CellBlock *cursor_header, *cursor;
|
||||
VirtualCellLocation vcell_loc;
|
||||
VirtualLocation save_loc;
|
||||
time_t present;
|
||||
gboolean start_primary_color = TRUE;
|
||||
|
||||
int new_entry_row = -1;
|
||||
int new_entry_row = -1;
|
||||
|
||||
if (!ledger) return;
|
||||
if (!ledger) return;
|
||||
|
||||
/* Load up cells */
|
||||
load_discount_type_cells (ledger);
|
||||
load_discount_how_cells (ledger);
|
||||
gnc_entry_ledger_load_xfer_cells (ledger);
|
||||
/* Load up cells */
|
||||
load_discount_type_cells (ledger);
|
||||
load_discount_how_cells (ledger);
|
||||
gnc_entry_ledger_load_xfer_cells (ledger);
|
||||
|
||||
blank_entry = gnc_entry_ledger_get_blank_entry (ledger);
|
||||
blank_entry = gnc_entry_ledger_get_blank_entry (ledger);
|
||||
|
||||
if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL)
|
||||
return;
|
||||
if (blank_entry == NULL && ledger->invoice == NULL && entry_list == NULL)
|
||||
return;
|
||||
|
||||
if (blank_entry == NULL && ledger->invoice) {
|
||||
switch (ledger->type) {
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
if (blank_entry == NULL && ledger->invoice)
|
||||
{
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_ORDER_ENTRY:
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_BILL_ENTRY:
|
||||
case GNCENTRY_EXPVOUCHER_ENTRY:
|
||||
|
||||
gnc_suspend_gui_refresh ();
|
||||
gnc_suspend_gui_refresh ();
|
||||
|
||||
blank_entry = gncEntryCreate (ledger->book);
|
||||
gncEntrySetDate (blank_entry, ledger->last_date_entered);
|
||||
ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
|
||||
blank_entry = gncEntryCreate (ledger->book);
|
||||
gncEntrySetDate (blank_entry, ledger->last_date_entered);
|
||||
ledger->blank_entry_guid = *gncEntryGetGUID (blank_entry);
|
||||
|
||||
gnc_resume_gui_refresh ();
|
||||
gnc_resume_gui_refresh ();
|
||||
|
||||
/* The rest of this does not apply to expense vouchers */
|
||||
if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
|
||||
{
|
||||
GncOwner *owner = gncInvoiceGetOwner (ledger->invoice);
|
||||
GncTaxTable *table = NULL;
|
||||
GncTaxIncluded taxincluded_p = GNC_TAXINCLUDED_USEGLOBAL;
|
||||
gboolean taxincluded = FALSE;
|
||||
gnc_numeric discount = gnc_numeric_zero ();
|
||||
GNCOptionDB *odb;
|
||||
/* The rest of this does not apply to expense vouchers */
|
||||
if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
|
||||
{
|
||||
GncOwner *owner = gncInvoiceGetOwner (ledger->invoice);
|
||||
GncTaxTable *table = NULL;
|
||||
GncTaxIncluded taxincluded_p = GNC_TAXINCLUDED_USEGLOBAL;
|
||||
gboolean taxincluded = FALSE;
|
||||
gnc_numeric discount = gnc_numeric_zero ();
|
||||
GNCOptionDB *odb;
|
||||
|
||||
/* Determine the TaxIncluded and Discount values */
|
||||
owner = gncOwnerGetEndOwner (owner);
|
||||
switch (gncOwnerGetType (owner)) {
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);
|
||||
discount = gncCustomerGetDiscount (owner->owner.customer);
|
||||
break;
|
||||
case GNC_OWNER_VENDOR:
|
||||
taxincluded_p = gncVendorGetTaxIncluded (owner->owner.vendor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* Determine the TaxIncluded and Discount values */
|
||||
owner = gncOwnerGetEndOwner (owner);
|
||||
switch (gncOwnerGetType (owner))
|
||||
{
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);
|
||||
discount = gncCustomerGetDiscount (owner->owner.customer);
|
||||
break;
|
||||
case GNC_OWNER_VENDOR:
|
||||
taxincluded_p = gncVendorGetTaxIncluded (owner->owner.vendor);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute the default taxincluded */
|
||||
switch (taxincluded_p) {
|
||||
case GNC_TAXINCLUDED_YES:
|
||||
taxincluded = TRUE;
|
||||
break;
|
||||
case GNC_TAXINCLUDED_NO:
|
||||
taxincluded = FALSE;
|
||||
break;
|
||||
case GNC_TAXINCLUDED_USEGLOBAL:
|
||||
if (ledger->gconf_section) {
|
||||
taxincluded = gnc_gconf_get_bool(ledger->gconf_section, "tax_included", NULL);
|
||||
} else {
|
||||
taxincluded = FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* Compute the default taxincluded */
|
||||
switch (taxincluded_p)
|
||||
{
|
||||
case GNC_TAXINCLUDED_YES:
|
||||
taxincluded = TRUE;
|
||||
break;
|
||||
case GNC_TAXINCLUDED_NO:
|
||||
taxincluded = FALSE;
|
||||
break;
|
||||
case GNC_TAXINCLUDED_USEGLOBAL:
|
||||
if (ledger->gconf_section)
|
||||
{
|
||||
taxincluded = gnc_gconf_get_bool(ledger->gconf_section, "tax_included", NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
taxincluded = FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute the proper taxtable */
|
||||
odb = gnc_option_db_new_for_type (GNC_ID_BOOK);
|
||||
gnc_option_db_load_from_kvp (odb, gnc_book_get_slots (ledger->book));
|
||||
/* Compute the proper taxtable */
|
||||
odb = gnc_option_db_new_for_type (GNC_ID_BOOK);
|
||||
gnc_option_db_load_from_kvp (odb, gnc_book_get_slots (ledger->book));
|
||||
|
||||
switch (gncOwnerGetType (owner)) {
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
table = gnc_option_db_lookup_taxtable_option (odb,
|
||||
"Business",
|
||||
"Default Customer TaxTable",
|
||||
NULL);
|
||||
switch (gncOwnerGetType (owner))
|
||||
{
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
table = gnc_option_db_lookup_taxtable_option (odb,
|
||||
"Business",
|
||||
"Default Customer TaxTable",
|
||||
NULL);
|
||||
|
||||
if (gncCustomerGetTaxTableOverride (owner->owner.customer))
|
||||
table = gncCustomerGetTaxTable (owner->owner.customer);
|
||||
break;
|
||||
if (gncCustomerGetTaxTableOverride (owner->owner.customer))
|
||||
table = gncCustomerGetTaxTable (owner->owner.customer);
|
||||
break;
|
||||
|
||||
case GNC_OWNER_VENDOR:
|
||||
table = gnc_option_db_lookup_taxtable_option (odb,
|
||||
"Business",
|
||||
"Default Vendor TaxTable",
|
||||
NULL);
|
||||
case GNC_OWNER_VENDOR:
|
||||
table = gnc_option_db_lookup_taxtable_option (odb,
|
||||
"Business",
|
||||
"Default Vendor TaxTable",
|
||||
NULL);
|
||||
|
||||
if (gncVendorGetTaxTableOverride (owner->owner.vendor))
|
||||
table = gncVendorGetTaxTable (owner->owner.vendor);
|
||||
break;
|
||||
if (gncVendorGetTaxTableOverride (owner->owner.vendor))
|
||||
table = gncVendorGetTaxTable (owner->owner.vendor);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gnc_option_db_destroy (odb);
|
||||
gnc_option_db_destroy (odb);
|
||||
|
||||
if (ledger->is_invoice) {
|
||||
gncEntrySetInvTaxTable (blank_entry, table);
|
||||
gncEntrySetInvTaxIncluded (blank_entry, taxincluded);
|
||||
gncEntrySetInvDiscount (blank_entry, discount);
|
||||
} else {
|
||||
gncEntrySetBillTaxTable (blank_entry, table);
|
||||
gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
|
||||
}
|
||||
}
|
||||
if (ledger->is_invoice)
|
||||
{
|
||||
gncEntrySetInvTaxTable (blank_entry, table);
|
||||
gncEntrySetInvTaxIncluded (blank_entry, taxincluded);
|
||||
gncEntrySetInvDiscount (blank_entry, discount);
|
||||
}
|
||||
else
|
||||
{
|
||||
gncEntrySetBillTaxTable (blank_entry, table);
|
||||
gncEntrySetBillTaxIncluded (blank_entry, taxincluded);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ledger->blank_entry_guid = *xaccGUIDNULL ();
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
ledger->blank_entry_guid = *xaccGUIDNULL ();
|
||||
break;
|
||||
}
|
||||
ledger->blank_entry_edited = FALSE;
|
||||
}
|
||||
ledger->blank_entry_edited = FALSE;
|
||||
}
|
||||
|
||||
table = ledger->table;
|
||||
table = ledger->table;
|
||||
|
||||
gnc_table_leave_update (table, table->current_cursor_loc);
|
||||
save_loc = table->current_cursor_loc;
|
||||
gnc_table_leave_update (table, table->current_cursor_loc);
|
||||
save_loc = table->current_cursor_loc;
|
||||
|
||||
/* Figure out where we are going to */
|
||||
if (ledger->traverse_to_new) {
|
||||
find_entry = blank_entry;
|
||||
} else if (ledger->hint_entry) {
|
||||
find_entry = ledger->hint_entry;
|
||||
} else {
|
||||
find_entry = gnc_entry_ledger_get_current_entry(ledger);
|
||||
/* XXX: get current entry (cursor_hint_xxx) */
|
||||
}
|
||||
/* Figure out where we are going to */
|
||||
if (ledger->traverse_to_new)
|
||||
{
|
||||
find_entry = blank_entry;
|
||||
}
|
||||
else if (ledger->hint_entry)
|
||||
{
|
||||
find_entry = ledger->hint_entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
find_entry = gnc_entry_ledger_get_current_entry(ledger);
|
||||
/* XXX: get current entry (cursor_hint_xxx) */
|
||||
}
|
||||
|
||||
/* If the current cursor has changed we save the values for later
|
||||
* possible restoration. */
|
||||
if (gnc_table_current_cursor_changed (table, TRUE) &&
|
||||
(find_entry == gnc_entry_ledger_get_current_entry (ledger)))
|
||||
{
|
||||
cursor_buffer = gnc_cursor_buffer_new ();
|
||||
gnc_table_save_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
else
|
||||
/* If the current cursor has changed we save the values for later
|
||||
* possible restoration. */
|
||||
if (gnc_table_current_cursor_changed (table, TRUE) &&
|
||||
(find_entry == gnc_entry_ledger_get_current_entry (ledger)))
|
||||
{
|
||||
cursor_buffer = gnc_cursor_buffer_new ();
|
||||
gnc_table_save_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
else
|
||||
cursor_buffer = NULL;
|
||||
|
||||
/* disable move callback -- we don't want the cascade of
|
||||
* callbacks while we are fiddling with loading the register */
|
||||
gnc_table_control_allow_move (table->control, FALSE);
|
||||
|
||||
/* invalidate the cursor */
|
||||
{
|
||||
VirtualLocation virt_loc;
|
||||
|
||||
virt_loc.vcell_loc.virt_row = -1;
|
||||
virt_loc.vcell_loc.virt_col = -1;
|
||||
virt_loc.phys_row_offset = -1;
|
||||
virt_loc.phys_col_offset = -1;
|
||||
|
||||
gnc_table_move_cursor_gui (table, virt_loc);
|
||||
}
|
||||
|
||||
/* make sure that the header is loaded */
|
||||
vcell_loc.virt_row = 0;
|
||||
vcell_loc.virt_col = 0;
|
||||
cursor_header = gnc_table_layout_get_cursor (table->layout, CURSOR_HEADER);
|
||||
gnc_table_set_vcell (table, cursor_header, NULL, TRUE, TRUE, vcell_loc);
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* get the current time and reset the dividing row */
|
||||
present = gnc_timet_get_today_end ();
|
||||
table->model->dividing_row = -1;
|
||||
cursor = gnc_table_layout_get_cursor (table->layout, "cursor");
|
||||
|
||||
/* Populate the table */
|
||||
for (node = entry_list; node; node = node->next)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
|
||||
/* Don't load the blank entry */
|
||||
if (entry == blank_entry)
|
||||
continue;
|
||||
|
||||
/* If this is the first load of the ledger, fill the quickfill cells */
|
||||
{
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
if (entry == find_entry)
|
||||
new_entry_row = vcell_loc.virt_row;
|
||||
|
||||
gnc_table_set_vcell (table, cursor, gncEntryGetGUID (entry),
|
||||
TRUE, start_primary_color, vcell_loc);
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* Flip color for the next guy */
|
||||
start_primary_color = !start_primary_color;
|
||||
}
|
||||
|
||||
/* Add the blank entry at the end. */
|
||||
if (blank_entry)
|
||||
{
|
||||
gnc_table_set_vcell (table, cursor, gncEntryGetGUID (blank_entry),
|
||||
TRUE, start_primary_color, vcell_loc);
|
||||
|
||||
if (find_entry == blank_entry)
|
||||
new_entry_row = vcell_loc.virt_row;
|
||||
|
||||
vcell_loc.virt_row++;
|
||||
}
|
||||
|
||||
/* Resize the table */
|
||||
gnc_table_set_size (table, vcell_loc.virt_row, 1);
|
||||
|
||||
/* Restore the cursor to its rightful position */
|
||||
if (new_entry_row > 0)
|
||||
save_loc.vcell_loc.virt_row = new_entry_row;
|
||||
|
||||
if (gnc_table_find_close_valid_cell (table, &save_loc, FALSE))
|
||||
{
|
||||
gnc_table_move_cursor_gui (table, save_loc);
|
||||
|
||||
if (find_entry == gnc_entry_ledger_get_current_entry (ledger))
|
||||
gnc_table_restore_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
|
||||
gnc_cursor_buffer_destroy (cursor_buffer);
|
||||
cursor_buffer = NULL;
|
||||
|
||||
/* disable move callback -- we don't want the cascade of
|
||||
* callbacks while we are fiddling with loading the register */
|
||||
gnc_table_control_allow_move (table->control, FALSE);
|
||||
/* Reset the ledger */
|
||||
ledger->traverse_to_new = FALSE;
|
||||
ledger->hint_entry = NULL;
|
||||
|
||||
/* invalidate the cursor */
|
||||
{
|
||||
VirtualLocation virt_loc;
|
||||
|
||||
virt_loc.vcell_loc.virt_row = -1;
|
||||
virt_loc.vcell_loc.virt_col = -1;
|
||||
virt_loc.phys_row_offset = -1;
|
||||
virt_loc.phys_col_offset = -1;
|
||||
|
||||
gnc_table_move_cursor_gui (table, virt_loc);
|
||||
}
|
||||
|
||||
/* make sure that the header is loaded */
|
||||
vcell_loc.virt_row = 0;
|
||||
vcell_loc.virt_col = 0;
|
||||
cursor_header = gnc_table_layout_get_cursor (table->layout, CURSOR_HEADER);
|
||||
gnc_table_set_vcell (table, cursor_header, NULL, TRUE, TRUE, vcell_loc);
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* get the current time and reset the dividing row */
|
||||
present = gnc_timet_get_today_end ();
|
||||
table->model->dividing_row = -1;
|
||||
cursor = gnc_table_layout_get_cursor (table->layout, "cursor");
|
||||
|
||||
/* Populate the table */
|
||||
for (node = entry_list; node; node = node->next) {
|
||||
GncEntry *entry = node->data;
|
||||
|
||||
/* Don't load the blank entry */
|
||||
if (entry == blank_entry)
|
||||
continue;
|
||||
|
||||
/* If this is the first load of the ledger, fill the quickfill cells */
|
||||
{
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
if (entry == find_entry)
|
||||
new_entry_row = vcell_loc.virt_row;
|
||||
|
||||
gnc_table_set_vcell (table, cursor, gncEntryGetGUID (entry),
|
||||
TRUE, start_primary_color, vcell_loc);
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* Flip color for the next guy */
|
||||
start_primary_color = !start_primary_color;
|
||||
}
|
||||
|
||||
/* Add the blank entry at the end. */
|
||||
if (blank_entry) {
|
||||
gnc_table_set_vcell (table, cursor, gncEntryGetGUID (blank_entry),
|
||||
TRUE, start_primary_color, vcell_loc);
|
||||
|
||||
if (find_entry == blank_entry)
|
||||
new_entry_row = vcell_loc.virt_row;
|
||||
|
||||
vcell_loc.virt_row++;
|
||||
}
|
||||
|
||||
/* Resize the table */
|
||||
gnc_table_set_size (table, vcell_loc.virt_row, 1);
|
||||
|
||||
/* Restore the cursor to its rightful position */
|
||||
if (new_entry_row > 0)
|
||||
save_loc.vcell_loc.virt_row = new_entry_row;
|
||||
|
||||
if (gnc_table_find_close_valid_cell (table, &save_loc, FALSE)) {
|
||||
gnc_table_move_cursor_gui (table, save_loc);
|
||||
|
||||
if (find_entry == gnc_entry_ledger_get_current_entry (ledger))
|
||||
gnc_table_restore_current_cursor (table, cursor_buffer);
|
||||
}
|
||||
|
||||
gnc_cursor_buffer_destroy (cursor_buffer);
|
||||
cursor_buffer = NULL;
|
||||
|
||||
/* Reset the ledger */
|
||||
ledger->traverse_to_new = FALSE;
|
||||
ledger->hint_entry = NULL;
|
||||
|
||||
/* Set the cell fractions */
|
||||
/* Set the cell fractions */
|
||||
|
||||
|
||||
gnc_table_refresh_gui (table, TRUE);
|
||||
gnc_entry_ledger_show_entry (ledger, table->current_cursor_loc.vcell_loc);
|
||||
gnc_table_refresh_gui (table, TRUE);
|
||||
gnc_entry_ledger_show_entry (ledger, table->current_cursor_loc.vcell_loc);
|
||||
|
||||
/* Set completion character */
|
||||
gnc_combo_cell_set_complete_char
|
||||
/* Set completion character */
|
||||
gnc_combo_cell_set_complete_char
|
||||
((ComboCell *)
|
||||
gnc_table_layout_get_cell (table->layout, ENTRY_IACCT_CELL),
|
||||
gnc_get_account_separator ());
|
||||
|
||||
gnc_combo_cell_set_complete_char
|
||||
gnc_combo_cell_set_complete_char
|
||||
((ComboCell *)
|
||||
gnc_table_layout_get_cell (table->layout, ENTRY_BACCT_CELL),
|
||||
gnc_get_account_separator ());
|
||||
|
||||
/* enable callback for cursor user-driven moves */
|
||||
gnc_table_control_allow_move (table->control, TRUE);
|
||||
/* enable callback for cursor user-driven moves */
|
||||
gnc_table_control_allow_move (table->control, TRUE);
|
||||
}
|
||||
|
||||
/* =========================== END OF FILE ========================== */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,55 +29,56 @@
|
||||
#include "table-allgui.h"
|
||||
#include "gncEntryLedger.h"
|
||||
|
||||
struct GncEntryLedger_s {
|
||||
GUID blank_entry_guid;
|
||||
gboolean blank_entry_edited;
|
||||
gboolean traverse_to_new;
|
||||
struct GncEntryLedger_s
|
||||
{
|
||||
GUID blank_entry_guid;
|
||||
gboolean blank_entry_edited;
|
||||
gboolean traverse_to_new;
|
||||
|
||||
gboolean loading; /* To keep from recursing from events */
|
||||
gboolean full_refresh; /* Is a full refresh ok? */
|
||||
gint component_id; /* To register for events */
|
||||
gboolean loading; /* To keep from recursing from events */
|
||||
gboolean full_refresh; /* Is a full refresh ok? */
|
||||
gint component_id; /* To register for events */
|
||||
|
||||
Timespec last_date_entered;
|
||||
Timespec last_date_entered;
|
||||
|
||||
GncEntry * hint_entry; /* A Hint for where to display */
|
||||
GncEntry * hint_entry; /* A Hint for where to display */
|
||||
|
||||
gncUIWidget parent;
|
||||
QofBook * book;
|
||||
Table * table;
|
||||
GncOrder * order;
|
||||
GncInvoice * invoice;
|
||||
QueryNew * query;
|
||||
|
||||
GncEntryLedgerType type;
|
||||
gncUIWidget parent;
|
||||
QofBook * book;
|
||||
Table * table;
|
||||
GncOrder * order;
|
||||
GncInvoice * invoice;
|
||||
QueryNew * query;
|
||||
|
||||
gboolean is_invoice; /* is this an invoice (or a bill)? */
|
||||
GncEntryLedgerType type;
|
||||
|
||||
const gchar * gconf_section;
|
||||
gboolean is_invoice; /* is this an invoice (or a bill)? */
|
||||
|
||||
const gchar * gconf_section;
|
||||
};
|
||||
|
||||
GncEntry * gnc_entry_ledger_get_entry (GncEntryLedger *ledger,
|
||||
VirtualCellLocation vcell_loc);
|
||||
VirtualCellLocation vcell_loc);
|
||||
Account * gnc_entry_ledger_get_account_by_name (GncEntryLedger *ledger, BasicCell * bcell,
|
||||
const char *name, gboolean *new);
|
||||
const char *name, gboolean *new);
|
||||
Account * gnc_entry_ledger_get_account (GncEntryLedger *ledger,
|
||||
const char * cell_name);
|
||||
const char * cell_name);
|
||||
GncTaxTable * gnc_entry_ledger_get_taxtable (GncEntryLedger *ledger,
|
||||
const char *cell_name);
|
||||
const char *cell_name);
|
||||
|
||||
gint gnc_entry_ledger_get_type (GncEntryLedger *ledger,
|
||||
const char * cell_name);
|
||||
const char * cell_name);
|
||||
gboolean gnc_entry_ledger_get_checkmark (GncEntryLedger *ledger,
|
||||
const char * cell_name);
|
||||
const char * cell_name);
|
||||
gboolean gnc_entry_ledger_get_numeric (GncEntryLedger *ledger,
|
||||
const char *cell_name,
|
||||
gnc_numeric *value);
|
||||
const char *cell_name,
|
||||
gnc_numeric *value);
|
||||
|
||||
const char * gnc_entry_ledger_type_string_getter (char flag);
|
||||
const char * gnc_entry_ledger_how_string_getter (char flag);
|
||||
|
||||
gboolean gnc_entry_ledger_find_entry (GncEntryLedger *ledger, GncEntry *entry,
|
||||
VirtualCellLocation *vcell_loc);
|
||||
VirtualCellLocation *vcell_loc);
|
||||
|
||||
void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger);
|
||||
|
||||
@@ -85,7 +86,7 @@ void gnc_entry_ledger_display_init (GncEntryLedger *ledger);
|
||||
void gnc_entry_ledger_display_fini (GncEntryLedger *ledger);
|
||||
|
||||
void gnc_entry_ledger_compute_value (GncEntryLedger *ledger,
|
||||
gnc_numeric *value,
|
||||
gnc_numeric *tax_value);
|
||||
gnc_numeric *value,
|
||||
gnc_numeric *tax_value);
|
||||
|
||||
#endif /* GNC_ENTRY_LEDGERP_H */
|
||||
|
||||
@@ -52,40 +52,40 @@
|
||||
|
||||
GncTaxTable*
|
||||
gnc_option_db_lookup_taxtable_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncTaxTable * default_value)
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncTaxTable * default_value)
|
||||
{
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_taxtable_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0);
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_taxtable_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncTaxTable"), 1, 0);
|
||||
}
|
||||
|
||||
GncInvoice*
|
||||
gnc_option_db_lookup_invoice_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncInvoice * default_value)
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncInvoice * default_value)
|
||||
{
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_invoice_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0);
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_invoice_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncInvoice"), 1, 0);
|
||||
}
|
||||
|
||||
GncCustomer*
|
||||
gnc_option_db_lookup_customer_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncCustomer * default_value)
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncCustomer * default_value)
|
||||
{
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_customer_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0);
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_customer_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncCustomer"), 1, 0);
|
||||
}
|
||||
|
||||
GncVendor*
|
||||
gnc_option_db_lookup_vendor_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncVendor * default_value)
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncVendor * default_value)
|
||||
{
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_vendor_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0);
|
||||
LOOKUP_OPTION("gnc_option_db_lookup_vendor_option");
|
||||
return SWIG_MustGetPtr(value, SWIG_TypeQuery("_p__gncVendor"), 1, 0);
|
||||
}
|
||||
|
||||
@@ -33,24 +33,24 @@
|
||||
|
||||
|
||||
GncTaxTable* gnc_option_db_lookup_taxtable_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncTaxTable * default_value);
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncTaxTable * default_value);
|
||||
|
||||
GncInvoice* gnc_option_db_lookup_invoice_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncInvoice * default_value);
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncInvoice * default_value);
|
||||
|
||||
GncCustomer* gnc_option_db_lookup_customer_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncCustomer * default_value);
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncCustomer * default_value);
|
||||
|
||||
GncVendor* gnc_option_db_lookup_vendor_option(GNCOptionDB *odb,
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncVendor * default_value);
|
||||
const char *section,
|
||||
const char *name,
|
||||
GncVendor * default_value);
|
||||
|
||||
|
||||
#endif /* GNC_BUSINESS_OPTIONS_UTILS_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user