2001-11-21 19:23:07 -06:00
|
|
|
/*
|
|
|
|
* gncOrder.c -- the Core Business Order
|
2002-02-03 14:01:08 -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 "kvp_frame.h"
|
|
|
|
#include "gnc-engine-util.h"
|
2003-06-24 18:48:58 -05:00
|
|
|
#include "gnc-book.h"
|
2003-06-26 02:27:52 -05:00
|
|
|
#include "GNCId.h"
|
2003-06-25 01:11:30 -05:00
|
|
|
#include "QueryCore.h"
|
2003-06-25 02:18:48 -05:00
|
|
|
#include "QueryNew.h"
|
2002-02-03 14:01:08 -06:00
|
|
|
#include "QueryObject.h"
|
2002-03-02 12:55:01 -06:00
|
|
|
#include "gnc-event-p.h"
|
2002-11-03 14:21:42 -06:00
|
|
|
#include "gnc-be-utils.h"
|
2003-06-26 02:27:52 -05:00
|
|
|
#include "qofid-p.h"
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
#include "gncBusiness.h"
|
|
|
|
#include "gncEntry.h"
|
|
|
|
#include "gncEntryP.h"
|
|
|
|
#include "gncOrder.h"
|
|
|
|
#include "gncOrderP.h"
|
2001-12-05 23:46:42 -06:00
|
|
|
#include "gncOwner.h"
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
struct _gncOrder {
|
2003-06-26 22:05:25 -05:00
|
|
|
QofBook *book;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
GUID guid;
|
|
|
|
char * id;
|
|
|
|
char * notes;
|
2002-02-26 22:52:33 -06:00
|
|
|
char * reference;
|
2002-02-23 22:01:57 -06:00
|
|
|
char * printname;
|
2001-12-05 23:46:42 -06:00
|
|
|
GncOwner owner;
|
2001-11-21 19:23:07 -06:00
|
|
|
GList * entries;
|
|
|
|
Timespec opened;
|
|
|
|
Timespec closed;
|
|
|
|
gboolean active;
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
int editlevel;
|
|
|
|
gboolean do_free;
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
gboolean dirty;
|
|
|
|
};
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
static short module = MOD_BUSINESS;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
#define _GNC_MOD_NAME GNC_ORDER_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));
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
#define SET_STR(obj, member, str) { \
|
2001-11-21 19:23:07 -06:00
|
|
|
char * tmp; \
|
|
|
|
\
|
|
|
|
if (!safe_strcmp (member, str)) return; \
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (obj); \
|
2001-11-21 19:23:07 -06:00
|
|
|
tmp = CACHE_INSERT (str); \
|
|
|
|
CACHE_REMOVE (member); \
|
|
|
|
member = tmp; \
|
|
|
|
}
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
static void addObj (GncOrder *order);
|
|
|
|
static void remObj (GncOrder *order);
|
|
|
|
|
2002-03-02 12:55:01 -06:00
|
|
|
G_INLINE_FUNC void mark_order (GncOrder *order);
|
|
|
|
G_INLINE_FUNC void
|
|
|
|
mark_order (GncOrder *order)
|
|
|
|
{
|
|
|
|
order->dirty = TRUE;
|
2002-11-03 14:21:42 -06:00
|
|
|
gncBusinessSetDirtyFlag (order->book, _GNC_MOD_NAME, TRUE);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
|
|
|
gnc_engine_generate_event (&order->guid, GNC_EVENT_MODIFY);
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Create/Destroy Functions */
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
GncOrder *gncOrderCreate (QofBook *book)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
GncOrder *order;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
if (!book) return NULL;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
order = g_new0 (GncOrder, 1);
|
2001-11-24 23:34:34 -06:00
|
|
|
order->book = book;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
order->id = CACHE_INSERT ("");
|
|
|
|
order->notes = CACHE_INSERT ("");
|
2002-02-26 22:52:33 -06:00
|
|
|
order->reference = CACHE_INSERT ("");
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
order->active = TRUE;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
xaccGUIDNew (&order->guid, book);
|
|
|
|
addObj (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-03-02 12:55:01 -06:00
|
|
|
gnc_engine_generate_event (&order->guid, GNC_EVENT_CREATE);
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gncOrderDestroy (GncOrder *order)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
|
|
|
if (!order) return;
|
|
|
|
order->do_free = TRUE;
|
|
|
|
gncOrderCommitEdit (order);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gncOrderFree (GncOrder *order)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!order) return;
|
|
|
|
|
2002-03-02 12:55:01 -06:00
|
|
|
gnc_engine_generate_event (&order->guid, GNC_EVENT_DESTROY);
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
g_list_free (order->entries);
|
|
|
|
CACHE_REMOVE (order->id);
|
|
|
|
CACHE_REMOVE (order->notes);
|
2002-02-26 22:52:33 -06:00
|
|
|
CACHE_REMOVE (order->reference);
|
2001-11-24 23:34:34 -06:00
|
|
|
remObj (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-02-23 22:01:57 -06:00
|
|
|
if (order->printname) g_free (order->printname);
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
g_free (order);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Functions */
|
|
|
|
|
|
|
|
void gncOrderSetGUID (GncOrder *order, const GUID *guid)
|
|
|
|
{
|
|
|
|
if (!order || !guid) return;
|
2001-11-24 23:34:34 -06:00
|
|
|
if (guid_equal (guid, &order->guid)) return;
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (order);
|
2001-11-24 23:34:34 -06:00
|
|
|
remObj (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
order->guid = *guid;
|
2001-11-24 23:34:34 -06:00
|
|
|
addObj (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOrderSetID (GncOrder *order, const char *id)
|
|
|
|
{
|
|
|
|
if (!order || !id) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (order, order->id, id);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
void gncOrderSetOwner (GncOrder *order, GncOwner *owner)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2001-12-05 23:46:42 -06:00
|
|
|
if (!order || !owner) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (gncOwnerEqual (&order->owner, owner)) return;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (order);
|
2001-12-05 23:46:42 -06:00
|
|
|
gncOwnerCopy (owner, &order->owner);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-02-27 18:55:34 -06:00
|
|
|
void gncOrderSetDateOpened (GncOrder *order, Timespec date)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-02-27 18:55:34 -06:00
|
|
|
if (!order) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (timespec_equal (&order->opened, &date)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (order);
|
2002-02-27 18:55:34 -06:00
|
|
|
order->opened = date;
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-02-27 18:55:34 -06:00
|
|
|
void gncOrderSetDateClosed (GncOrder *order, Timespec date)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-02-27 18:55:34 -06:00
|
|
|
if (!order) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (timespec_equal (&order->closed, &date)) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (order);
|
2002-02-27 18:55:34 -06:00
|
|
|
order->closed = date;
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOrderSetNotes (GncOrder *order, const char *notes)
|
|
|
|
{
|
|
|
|
if (!order || !notes) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (order, order->notes, notes);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-02-26 22:52:33 -06:00
|
|
|
void gncOrderSetReference (GncOrder *order, const char *reference)
|
|
|
|
{
|
|
|
|
if (!order || !reference) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR (order, order->reference, reference);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2002-02-26 22:52:33 -06:00
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncOrderSetActive (GncOrder *order, gboolean active)
|
|
|
|
{
|
|
|
|
if (!order) return;
|
2002-06-21 14:00:34 -05:00
|
|
|
if (order->active == active) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderBeginEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
order->active = active;
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncOrderCommitEdit (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOrderSetDirty (GncOrder *order, gboolean dirty)
|
|
|
|
{
|
|
|
|
if (!order) return;
|
|
|
|
order->dirty = dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an Entry to the Order */
|
|
|
|
void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
|
|
|
|
{
|
|
|
|
GncOrder *old;
|
|
|
|
|
|
|
|
if (!order || !entry) return;
|
|
|
|
|
|
|
|
old = gncEntryGetOrder (entry);
|
|
|
|
if (old == order) return; /* I already own it */
|
|
|
|
if (old) gncOrderRemoveEntry (old, entry);
|
|
|
|
|
2002-02-27 23:10:07 -06:00
|
|
|
order->entries = g_list_insert_sorted (order->entries, entry,
|
|
|
|
(GCompareFunc)gncEntryCompare);
|
2002-02-28 22:15:01 -06:00
|
|
|
|
|
|
|
/* This will send out an event -- make sure we're attached */
|
|
|
|
gncEntrySetOrder (entry, order);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
|
|
|
|
{
|
|
|
|
if (!order || !entry) return;
|
|
|
|
|
|
|
|
gncEntrySetOrder (entry, NULL);
|
|
|
|
order->entries = g_list_remove (order->entries, entry);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_order (order);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Functions */
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
QofBook * gncOrderGetBook (GncOrder *order)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
2001-11-24 23:34:34 -06:00
|
|
|
return order->book;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const GUID * gncOrderGetGUID (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
|
|
|
return &(order->guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * gncOrderGetID (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
|
|
|
return order->id;
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
GncOwner * gncOrderGetOwner (GncOrder *order)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
2001-12-05 23:46:42 -06:00
|
|
|
return &order->owner;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Timespec gncOrderGetDateOpened (GncOrder *order)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!order) return ts;
|
|
|
|
return order->opened;
|
|
|
|
}
|
|
|
|
|
|
|
|
Timespec gncOrderGetDateClosed (GncOrder *order)
|
|
|
|
{
|
|
|
|
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
|
|
|
if (!order) return ts;
|
|
|
|
return order->closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * gncOrderGetNotes (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
|
|
|
return order->notes;
|
|
|
|
}
|
|
|
|
|
2002-02-26 22:52:33 -06:00
|
|
|
const char * gncOrderGetReference (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
|
|
|
return order->reference;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
gboolean gncOrderGetActive (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return FALSE;
|
|
|
|
return order->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the list Entries */
|
|
|
|
GList * gncOrderGetEntries (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return NULL;
|
|
|
|
return order->entries;
|
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
GncOrder * gncOrderLookup (QofBook *book, const GUID *guid)
|
2001-11-24 23:34:34 -06:00
|
|
|
{
|
|
|
|
if (!book || !guid) return NULL;
|
|
|
|
return xaccLookupEntity (gnc_book_get_entity_table (book),
|
|
|
|
guid, _GNC_MOD_NAME);
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
gboolean gncOrderIsDirty (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return FALSE;
|
|
|
|
return order->dirty;
|
|
|
|
}
|
|
|
|
|
2002-02-19 12:23:53 -06:00
|
|
|
gboolean gncOrderIsClosed (GncOrder *order)
|
|
|
|
{
|
|
|
|
if (!order) return FALSE;
|
|
|
|
if (order->closed.tv_sec || order->closed.tv_nsec) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncOrderBeginEdit (GncOrder *order)
|
|
|
|
{
|
2002-11-03 14:21:42 -06:00
|
|
|
GNC_BEGIN_EDIT (order, _GNC_MOD_NAME);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static void gncOrderOnError (GncOrder *order, QofBackendError errcode)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-11-03 14:21:42 -06:00
|
|
|
PERR("Order Backend Failure: %d", errcode);
|
|
|
|
}
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
static void gncOrderOnDone (GncOrder *order)
|
|
|
|
{
|
2002-03-04 13:34:52 -06:00
|
|
|
order->dirty = FALSE;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncOrderCommitEdit (GncOrder *order)
|
|
|
|
{
|
|
|
|
GNC_COMMIT_EDIT_PART1 (order);
|
|
|
|
GNC_COMMIT_EDIT_PART2 (order, _GNC_MOD_NAME, gncOrderOnError,
|
|
|
|
gncOrderOnDone, gncOrderFree);
|
|
|
|
}
|
|
|
|
|
2002-02-03 14:01:08 -06:00
|
|
|
int gncOrderCompare (GncOrder *a, GncOrder *b)
|
|
|
|
{
|
|
|
|
int compare;
|
|
|
|
|
|
|
|
if (a == b) return 0;
|
|
|
|
if (!a && b) return -1;
|
|
|
|
if (a && !b) return 1;
|
|
|
|
|
|
|
|
compare = safe_strcmp (a->id, b->id);
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->opened), &(b->opened));
|
2002-02-27 23:10:07 -06:00
|
|
|
if (compare) return compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
|
|
|
compare = timespec_cmp (&(a->closed), &(b->closed));
|
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 (GncOrder *order)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessAddObject (order->book, _GNC_MOD_NAME, order, &order->guid);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void remObj (GncOrder *order)
|
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessRemoveObject (order->book, _GNC_MOD_NAME, &order->guid);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static void _gncOrderCreate (QofBook *book)
|
2001-11-24 23:34:34 -06:00
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessCreate (book, _GNC_MOD_NAME);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static void _gncOrderDestroy (QofBook *book)
|
2001-11-24 23:34:34 -06:00
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
|
|
|
}
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static gboolean _gncOrderIsDirty (QofBook *book)
|
2002-02-24 16:12:24 -06:00
|
|
|
{
|
|
|
|
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static void _gncOrderMarkClean (QofBook *book)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
static void _gncOrderForeach (QofBook *book, foreachObjectCB cb,
|
2002-02-03 14:01:08 -06:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
|
|
|
}
|
|
|
|
|
2002-02-24 16:12:24 -06:00
|
|
|
static const char * _gncOrderPrintable (gpointer obj)
|
2002-02-23 22:01:57 -06:00
|
|
|
{
|
2002-02-24 16:12:24 -06:00
|
|
|
GncOrder *order = obj;
|
|
|
|
|
2002-02-23 22:01:57 -06:00
|
|
|
g_return_val_if_fail (order, NULL);
|
|
|
|
|
|
|
|
if (order->dirty || order->printname == NULL) {
|
|
|
|
if (order->printname) g_free (order->printname);
|
|
|
|
|
|
|
|
order->printname =
|
|
|
|
g_strdup_printf ("%s%s", order->id,
|
|
|
|
gncOrderIsClosed (order) ? _(" (closed)") : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return order->printname;
|
|
|
|
}
|
|
|
|
|
2003-06-26 22:09:39 -05:00
|
|
|
static QofObject gncOrderDesc = {
|
2003-06-26 22:05:25 -05:00
|
|
|
QOF_OBJECT_VERSION,
|
2001-11-24 23:34:34 -06:00
|
|
|
_GNC_MOD_NAME,
|
2002-02-19 12:23:53 -06:00
|
|
|
"Order",
|
2001-11-24 23:34:34 -06:00
|
|
|
_gncOrderCreate,
|
|
|
|
_gncOrderDestroy,
|
2002-02-24 16:12:24 -06:00
|
|
|
_gncOrderIsDirty,
|
2002-03-04 13:34:52 -06:00
|
|
|
_gncOrderMarkClean,
|
2002-02-03 14:01:08 -06:00
|
|
|
_gncOrderForeach,
|
2002-02-23 22:01:57 -06:00
|
|
|
_gncOrderPrintable,
|
2001-11-21 19:23:07 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
gboolean gncOrderRegister (void)
|
|
|
|
{
|
2002-02-03 14:01:08 -06:00
|
|
|
static QueryObjectDef params[] = {
|
2002-02-08 22:18:50 -06:00
|
|
|
{ ORDER_ID, QUERYCORE_STRING, (QueryAccess)gncOrderGetID },
|
2002-05-13 19:52:42 -05:00
|
|
|
{ ORDER_REFERENCE, QUERYCORE_STRING, (QueryAccess)gncOrderGetReference },
|
2002-02-03 20:53:13 -06:00
|
|
|
{ ORDER_OWNER, GNC_OWNER_MODULE_NAME, (QueryAccess)gncOrderGetOwner },
|
2002-02-08 22:18:50 -06:00
|
|
|
{ ORDER_OPENED, QUERYCORE_DATE, (QueryAccess)gncOrderGetDateOpened },
|
2002-02-19 12:23:53 -06:00
|
|
|
{ ORDER_IS_CLOSED, QUERYCORE_BOOLEAN, (QueryAccess)gncOrderIsClosed },
|
2002-02-08 22:18:50 -06:00
|
|
|
{ ORDER_CLOSED, QUERYCORE_DATE, (QueryAccess)gncOrderGetDateClosed },
|
|
|
|
{ ORDER_NOTES, QUERYCORE_STRING, (QueryAccess)gncOrderGetNotes },
|
2002-02-03 19:55:33 -06:00
|
|
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncOrderGetBook },
|
2002-02-24 16:12:24 -06:00
|
|
|
{ QUERY_PARAM_GUID, QUERYCORE_GUID, (QueryAccess)gncOrderGetGUID },
|
2003-01-14 21:49:51 -06:00
|
|
|
{ QUERY_PARAM_ACTIVE, QUERYCORE_BOOLEAN, (QueryAccess)gncOrderGetActive },
|
2002-02-03 14:01:08 -06:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2002-02-03 19:55:33 -06:00
|
|
|
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncOrderCompare, params);
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2003-06-26 22:09:39 -05:00
|
|
|
return qof_object_register (&gncOrderDesc);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
gint64 gncOrderNextID (QofBook *book)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2002-03-02 20:17:07 -06:00
|
|
|
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|