2001-11-21 19:23:07 -06:00
|
|
|
/*
|
|
|
|
* gncEntry.c -- the Core Business Entry Interface
|
2002-01-20 20:27:02 -06:00
|
|
|
* Copyright (C) 2001,2002 Derek Atkins
|
2001-11-21 19:23:07 -06:00
|
|
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "messages.h"
|
|
|
|
#include "gnc-numeric.h"
|
|
|
|
#include "gnc-engine-util.h"
|
2001-11-24 23:34:34 -06:00
|
|
|
#include "gnc-book-p.h"
|
|
|
|
#include "GNCIdP.h"
|
2002-02-03 14:01:08 -06:00
|
|
|
#include "QueryObject.h"
|
2002-02-28 22:15:01 -06:00
|
|
|
#include "gnc-event-p.h"
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
#include "gncBusiness.h"
|
|
|
|
#include "gncEntry.h"
|
|
|
|
#include "gncEntryP.h"
|
|
|
|
#include "gncInvoice.h"
|
|
|
|
#include "gncOrder.h"
|
|
|
|
|
|
|
|
struct _gncEntry {
|
2001-11-24 23:34:34 -06:00
|
|
|
GNCBook * book;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
GUID guid;
|
|
|
|
Timespec date;
|
2002-02-27 23:10:07 -06:00
|
|
|
Timespec date_entered;
|
2001-11-21 19:23:07 -06:00
|
|
|
char * desc;
|
|
|
|
char * action;
|
|
|
|
gnc_numeric quantity;
|
|
|
|
gnc_numeric price;
|
|
|
|
gnc_numeric tax;
|
2001-11-23 23:35:08 -06:00
|
|
|
gint tax_type;
|
2001-11-21 19:23:07 -06:00
|
|
|
gnc_numeric discount;
|
2001-11-23 23:35:08 -06:00
|
|
|
gint disc_type;
|
2001-11-21 19:23:07 -06:00
|
|
|
Account * account;
|
|
|
|
Account * taxaccount;
|
|
|
|
|
|
|
|
GncOrder * order;
|
|
|
|
GncInvoice * invoice;
|
|
|
|
|
|
|
|
gboolean dirty;
|
|
|
|
};
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
#define _GNC_MOD_NAME GNC_ENTRY_MODULE_NAME
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
|
|
|
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
|
|
|
|
|
|
|
#define SET_STR(member, str) { \
|
|
|
|
char * tmp; \
|
|
|
|
\
|
|
|
|
if (!safe_strcmp (member, str)) return; \
|
|
|
|
tmp = CACHE_INSERT (str); \
|
|
|
|
CACHE_REMOVE (member); \
|
|
|
|
member = tmp; \
|
|
|
|
}
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
static void addObj (GncEntry *entry);
|
|
|
|
static void remObj (GncEntry *entry);
|
|
|
|
|
2001-11-26 17:30:33 -06:00
|
|
|
static char * typeStrs[] = {
|
|
|
|
N_("Value"),
|
|
|
|
N_("Percent"),
|
|
|
|
N_("Value/Pretax"),
|
|
|
|
N_("Percent/Pretax")
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *gncEntryGetTaxTypeStr (gint type)
|
|
|
|
{
|
|
|
|
return typeStrs[type & 0x01]; /* Only 0, 1 */
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *gncEntryGetDiscountTypeStr (gint type)
|
|
|
|
{
|
|
|
|
return typeStrs[type & 0x03]; /* Only 0, 1, 2, 3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
gint gncEntryGetTypeFromStr (const char *type)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
if (!safe_strcmp (typeStrs[i], type))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-02-28 22:15:01 -06:00
|
|
|
G_INLINE_FUNC void mark_entry (GncEntry *entry);
|
|
|
|
G_INLINE_FUNC void
|
|
|
|
mark_entry (GncEntry *entry)
|
|
|
|
{
|
|
|
|
entry->dirty = TRUE;
|
|
|
|
|
|
|
|
gnc_engine_generate_event (&entry->guid, GNC_EVENT_MODIFY);
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Create/Destroy Functions */
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
GncEntry *gncEntryCreate (GNCBook *book)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
GncEntry *entry;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
if (!book) return NULL;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
entry = g_new0 (GncEntry, 1);
|
2001-11-24 23:34:34 -06:00
|
|
|
entry->book = book;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
entry->desc = CACHE_INSERT ("");
|
|
|
|
entry->action = CACHE_INSERT ("");
|
|
|
|
|
|
|
|
{
|
|
|
|
gnc_numeric zero = gnc_numeric_zero ();
|
2002-02-28 22:15:01 -06:00
|
|
|
entry->quantity = zero;
|
|
|
|
entry->price = zero;
|
|
|
|
entry->tax = zero;
|
|
|
|
entry->discount = zero;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
2002-02-05 14:27:10 -06:00
|
|
|
entry->tax_type = GNC_ENTRY_INTERP_PERCENT;
|
|
|
|
entry->disc_type = GNC_ENTRY_INTERP_PERCENT;
|
2001-11-21 19:23:07 -06:00
|
|
|
entry->dirty = FALSE;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
xaccGUIDNew (&entry->guid, book);
|
|
|
|
addObj (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-02-28 22:15:01 -06:00
|
|
|
gnc_engine_generate_event (&entry->guid, GNC_EVENT_CREATE);
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntryDestroy (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
|
2002-02-28 22:15:01 -06:00
|
|
|
gnc_engine_generate_event (&entry->guid, GNC_EVENT_DESTROY);
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
CACHE_REMOVE (entry->desc);
|
|
|
|
CACHE_REMOVE (entry->action);
|
2001-11-24 23:34:34 -06:00
|
|
|
remObj (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
g_free (entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Functions */
|
|
|
|
|
|
|
|
void gncEntrySetGUID (GncEntry *entry, const GUID *guid)
|
|
|
|
{
|
|
|
|
if (!entry || !guid) return;
|
2001-11-24 23:34:34 -06:00
|
|
|
if (guid_equal (guid, &entry->guid)) return;
|
|
|
|
|
|
|
|
remObj (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
entry->guid = *guid;
|
2001-11-24 23:34:34 -06:00
|
|
|
addObj (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
void gncEntrySetDate (GncEntry *entry, Timespec date)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-02-27 23:10:07 -06:00
|
|
|
if (!entry) return;
|
|
|
|
entry->date = date;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2002-02-27 23:10:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->date_entered = date;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDescription (GncEntry *entry, const char *desc)
|
|
|
|
{
|
|
|
|
if (!entry || !desc) return;
|
|
|
|
SET_STR (entry->desc, desc);
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetAction (GncEntry *entry, const char *action)
|
|
|
|
{
|
|
|
|
if (!entry || !action) return;
|
|
|
|
SET_STR (entry->action, action);
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->quantity = quantity;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetPrice (GncEntry *entry, gnc_numeric price)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->price = price;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetTax (GncEntry *entry, gnc_numeric tax)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->tax = tax;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDiscount (GncEntry *entry, gnc_numeric discount)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->discount = discount;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetAccount (GncEntry *entry, Account *acc)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->account = acc;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetTaxAccount (GncEntry *entry, Account *acc)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->taxaccount = acc;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Called from gncOrder when we're added to the Order */
|
|
|
|
void gncEntrySetOrder (GncEntry *entry, GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->order = order;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
|
|
|
|
|
|
|
/* Generate an event modifying the Order's end-owner */
|
|
|
|
gnc_engine_generate_event (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
|
|
|
|
GNC_EVENT_MODIFY);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called from gncInvoice when we're added to the Invoice */
|
|
|
|
void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->invoice = invoice;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2001-11-23 23:35:08 -06:00
|
|
|
void gncEntrySetTaxType (GncEntry *entry, gint type)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
2001-11-26 17:30:33 -06:00
|
|
|
if (type < 0 || type > 1) return;
|
2001-11-23 23:35:08 -06:00
|
|
|
|
|
|
|
entry->tax_type = type;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncEntrySetDiscountType (GncEntry *entry, gint type)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
if (type < 0 || type > 3) return;
|
|
|
|
|
|
|
|
entry->disc_type = type;
|
2002-02-28 22:15:01 -06:00
|
|
|
mark_entry (entry);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncEntrySetDirty (GncEntry *entry, gboolean dirty)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
entry->dirty = dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Functions */
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
GNCBook * gncEntryGetBook (GncEntry *entry)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
2001-11-24 23:34:34 -06:00
|
|
|
return entry->book;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const GUID * gncEntryGetGUID (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return &(entry->guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
Timespec gncEntryGetDate (GncEntry *entry)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!entry) return ts;
|
|
|
|
return entry->date;
|
|
|
|
}
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
Timespec gncEntryGetDateEntered (GncEntry *entry)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!entry) return ts;
|
|
|
|
return entry->date_entered;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
const char * gncEntryGetDescription (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * gncEntryGetAction (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->action;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryGetQuantity (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->quantity;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryGetPrice (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->price;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryGetTax (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->tax;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryGetDiscount (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return gnc_numeric_zero();
|
|
|
|
return entry->discount;
|
|
|
|
}
|
|
|
|
|
|
|
|
Account * gncEntryGetAccount (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->account;
|
|
|
|
}
|
|
|
|
|
|
|
|
Account * gncEntryGetTaxAccount (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->taxaccount;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncInvoice * gncEntryGetInvoice (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->invoice;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncOrder * gncEntryGetOrder (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return NULL;
|
|
|
|
return entry->order;
|
|
|
|
}
|
|
|
|
|
2001-11-23 23:35:08 -06:00
|
|
|
gint gncEntryGetTaxType (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return 0;
|
|
|
|
return entry->tax_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint gncEntryGetDiscountType (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return 0;
|
|
|
|
return entry->disc_type;
|
|
|
|
}
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
GncEntry * gncEntryLookup (GNCBook *book, const GUID *guid)
|
|
|
|
{
|
|
|
|
if (!book || !guid) return NULL;
|
|
|
|
return xaccLookupEntity (gnc_book_get_entity_table (book),
|
|
|
|
guid, _GNC_MOD_NAME);
|
|
|
|
}
|
|
|
|
|
2002-01-20 20:27:02 -06:00
|
|
|
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
|
|
|
gnc_numeric tax, gint tax_type,
|
|
|
|
gnc_numeric discount, gint discount_type,
|
|
|
|
gnc_numeric *value, gnc_numeric *tax_value)
|
2002-01-12 22:25:55 -06:00
|
|
|
{
|
|
|
|
gnc_numeric subtotal;
|
|
|
|
gnc_numeric this_value;
|
2002-01-21 16:59:44 -06:00
|
|
|
gnc_numeric percent = gnc_numeric_create (100, 1);
|
2002-01-12 22:25:55 -06:00
|
|
|
|
|
|
|
/* Compute the value */
|
|
|
|
|
2002-01-20 20:27:02 -06:00
|
|
|
subtotal = gnc_numeric_mul (qty, price, 100, /* XXX */ GNC_RND_ROUND);
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-01-21 16:59:44 -06:00
|
|
|
if (GNC_ENTRY_INTERP_IS_PERCENT (discount_type)) {
|
|
|
|
discount = gnc_numeric_div (discount, percent, 10000 /* XXX */, GNC_RND_ROUND);
|
|
|
|
discount = gnc_numeric_mul (subtotal, discount, 10000 /* XXX */, GNC_RND_ROUND);
|
|
|
|
}
|
2002-01-12 22:25:55 -06:00
|
|
|
|
2002-01-21 16:59:44 -06:00
|
|
|
this_value = gnc_numeric_sub (subtotal, discount, 10000 /* XXX */, GNC_RND_ROUND);
|
2002-01-20 20:27:02 -06:00
|
|
|
if (discount_type & GNC_ENTRY_PRETAX_FLAG)
|
2002-01-12 22:25:55 -06:00
|
|
|
subtotal = this_value;
|
|
|
|
|
|
|
|
if (value != NULL)
|
|
|
|
*value = this_value;
|
|
|
|
|
2002-01-20 20:27:02 -06:00
|
|
|
/* Now... Compute the tax value (if the caller wants it) */
|
2002-01-12 22:25:55 -06:00
|
|
|
|
|
|
|
if (tax_value != NULL) {
|
2002-01-21 16:59:44 -06:00
|
|
|
if (GNC_ENTRY_INTERP_IS_PERCENT (tax_type)) {
|
|
|
|
tax = gnc_numeric_div (tax, percent, 10000 /* XXX */, GNC_RND_ROUND);
|
|
|
|
tax = gnc_numeric_mul (subtotal, tax, 10000 /* XXX */, GNC_RND_ROUND);
|
|
|
|
}
|
2002-01-12 22:25:55 -06:00
|
|
|
|
|
|
|
*tax_value = tax;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-20 20:27:02 -06:00
|
|
|
void gncEntryGetValue (GncEntry *entry, gnc_numeric *value,
|
|
|
|
gnc_numeric *tax_value)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
|
|
|
|
return gncEntryComputeValue (gncEntryGetQuantity (entry),
|
|
|
|
gncEntryGetPrice (entry),
|
|
|
|
gncEntryGetTax (entry),
|
|
|
|
gncEntryGetTaxType (entry),
|
|
|
|
gncEntryGetDiscount (entry),
|
|
|
|
gncEntryGetDiscountType (entry),
|
|
|
|
value, tax_value);
|
|
|
|
}
|
|
|
|
|
2002-02-24 23:02:21 -06:00
|
|
|
gnc_numeric gncEntryReturnValue (GncEntry *entry)
|
|
|
|
{
|
|
|
|
gnc_numeric val = gnc_numeric_zero ();
|
|
|
|
if (!entry) return val;
|
|
|
|
gncEntryGetValue (entry, &val, NULL);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric gncEntryReturnTaxValue (GncEntry *entry)
|
|
|
|
{
|
|
|
|
gnc_numeric val = gnc_numeric_zero ();
|
|
|
|
if (!entry) return val;
|
|
|
|
gncEntryGetValue (entry, NULL, &val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncEntryCommitEdit (GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!entry) return;
|
|
|
|
/* XXX */
|
|
|
|
}
|
|
|
|
|
2002-02-03 14:01:08 -06:00
|
|
|
int gncEntryCompare (GncEntry *a, GncEntry *b)
|
|
|
|
{
|
|
|
|
int compare;
|
|
|
|
|
|
|
|
if (a == b) return 0;
|
|
|
|
if (!a && b) return -1;
|
|
|
|
if (a && !b) return 1;
|
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->date), &(b->date));
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->date_entered), &(b->date_entered));
|
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = safe_strcmp (a->desc, b->desc);
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = safe_strcmp (a->action, b->action);
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
return guid_compare (&(a->guid), &(b->guid));
|
|
|
|
}
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
/* Package-Private functions */
|
|
|
|
|
|
|
|
static void addObj (GncEntry *entry)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessAddObject (entry->book, _GNC_MOD_NAME, entry, &entry->guid);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void remObj (GncEntry *entry)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessRemoveObject (entry->book, _GNC_MOD_NAME, &entry->guid);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _gncEntryCreate (GNCBook *book)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessCreate (book, _GNC_MOD_NAME);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _gncEntryDestroy (GNCBook *book)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
|
|
|
}
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2002-02-24 16:12:24 -06:00
|
|
|
static gboolean _gncEntryIsDirty (GNCBook *book)
|
|
|
|
{
|
|
|
|
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
2002-02-03 14:01:08 -06:00
|
|
|
static void _gncEntryForeach (GNCBook *book, foreachObjectCB cb,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GncObject_t gncEntryDesc = {
|
|
|
|
GNC_OBJECT_VERSION,
|
2001-11-24 23:34:34 -06:00
|
|
|
_GNC_MOD_NAME,
|
2001-11-21 19:23:07 -06:00
|
|
|
"Order/Invoice Entry",
|
2001-11-24 23:34:34 -06:00
|
|
|
_gncEntryCreate,
|
|
|
|
_gncEntryDestroy,
|
2002-02-24 16:12:24 -06:00
|
|
|
_gncEntryIsDirty,
|
2002-02-03 14:01:08 -06:00
|
|
|
_gncEntryForeach,
|
2001-11-21 19:23:07 -06:00
|
|
|
NULL /* printable */
|
|
|
|
};
|
|
|
|
|
|
|
|
gboolean gncEntryRegister (void)
|
|
|
|
{
|
2002-02-03 14:01:08 -06:00
|
|
|
static QueryObjectDef params[] = {
|
|
|
|
{ ENTRY_DATE, QUERYCORE_DATE, (QueryAccess)gncEntryGetDate },
|
|
|
|
{ ENTRY_DESC, QUERYCORE_STRING, (QueryAccess)gncEntryGetDescription },
|
|
|
|
{ ENTRY_ACTION, QUERYCORE_STRING, (QueryAccess)gncEntryGetAction },
|
|
|
|
{ ENTRY_QTY, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetQuantity },
|
|
|
|
{ ENTRY_PRICE, QUERYCORE_NUMERIC, (QueryAccess)gncEntryGetPrice },
|
2002-02-03 19:55:33 -06:00
|
|
|
{ ENTRY_INVOICE, GNC_INVOICE_MODULE_NAME, (QueryAccess)gncEntryGetInvoice },
|
|
|
|
{ ENTRY_ORDER, GNC_ORDER_MODULE_NAME, (QueryAccess)gncEntryGetOrder },
|
2002-02-24 16:12:24 -06:00
|
|
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncEntryGetBook },
|
|
|
|
{ QUERY_PARAM_GUID, QUERYCORE_GUID, (QueryAccess)gncEntryGetGUID },
|
2002-02-03 14:01:08 -06:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2002-02-03 19:55:33 -06:00
|
|
|
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncEntryCompare, params);
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
return gncObjectRegister (&gncEntryDesc);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|